Line data Source code
1 : ///
2 : /// @file ar/internal/files/filesystem_file_tests.cpp
3 : /// @copyright (c) 2015 by Petr Zemek (s3rvac@gmail.com) and contributors
4 : /// @license MIT, see the @c LICENSE file for more details
5 : /// @brief Tests for the @c filesystem_file module.
6 : ///
7 :
8 : #include <gtest/gtest.h>
9 :
10 : #include "ar/internal/files/filesystem_file.h"
11 : #include "ar/internal/utilities/os.h"
12 : #include "ar/test_utilities/tmp_file.h"
13 :
14 : using namespace ar::tests;
15 :
16 : namespace ar {
17 : namespace internal {
18 : namespace tests {
19 :
20 : ///
21 : /// Tests for FilesystemFile.
22 : ///
23 8 : class FilesystemFileTests: public testing::Test {};
24 :
25 5 : TEST_F(FilesystemFileTests,
26 : GetNameReturnsCorrectValueWhenNoCustomNameIsGiven) {
27 : #ifdef AR_OS_WINDOWS
28 : FilesystemFile file{R"(C:\\/path/to/file.txt)"};
29 : #else
30 2 : FilesystemFile file{"/path/to/file.txt"};
31 : #endif
32 :
33 1 : ASSERT_EQ("file.txt", file.getName());
34 : }
35 :
36 5 : TEST_F(FilesystemFileTests,
37 : GetNameReturnsCorrectValueWhenCustomNameIsGiven) {
38 2 : FilesystemFile file{"/path/to/file.txt", "another_file.txt"};
39 :
40 1 : ASSERT_EQ("another_file.txt", file.getName());
41 : }
42 :
43 5 : TEST_F(FilesystemFileTests,
44 : GetContentReturnsCorrectContent) {
45 2 : auto tmpFile = TmpFile::createWithContent("content");
46 2 : FilesystemFile file{tmpFile->getPath()};
47 :
48 1 : ASSERT_EQ("content", file.getContent());
49 : }
50 :
51 5 : TEST_F(FilesystemFileTests,
52 : SaveCopyToSavesCopyOfFileToGivenDirectory) {
53 2 : const std::string Content{"content"};
54 2 : auto tmpFile = TmpFile::createWithContent(Content);
55 2 : const std::string Name{"ar-filesystemfile-file-save-copy-to-test.txt"};
56 2 : FilesystemFile file{tmpFile->getPath(), Name};
57 :
58 1 : file.saveCopyTo(".");
59 :
60 2 : RemoveFileOnDestruction remover{Name};
61 1 : ASSERT_EQ(Content, readFile(Name));
62 : }
63 :
64 : } // namespace tests
65 : } // namespace internal
66 3 : } // namespace ar
|