Line data Source code
1 : ///
2 : /// @file ar/internal/files/string_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 string_file module.
6 : ///
7 :
8 : #include <gtest/gtest.h>
9 :
10 : #include "ar/internal/files/string_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 StringFile.
22 : ///
23 8 : class StringFileTests: public testing::Test {};
24 :
25 5 : TEST_F(StringFileTests,
26 : FileHasCorrectContentUponCreation) {
27 2 : StringFile file{"content"};
28 :
29 1 : ASSERT_EQ("content", file.getContent());
30 : }
31 :
32 5 : TEST_F(StringFileTests,
33 : GetNameReturnsCorrectNameWhenFileHasName) {
34 2 : StringFile file{"content", "file.txt"};
35 :
36 1 : ASSERT_EQ("file.txt", file.getName());
37 : }
38 :
39 5 : TEST_F(StringFileTests,
40 : GetNameReturnsEmptyStringWhenFileHasNoName) {
41 2 : StringFile file{"content"};
42 :
43 1 : ASSERT_EQ("", file.getName());
44 : }
45 :
46 5 : TEST_F(StringFileTests,
47 : SaveCopyToSavesCopyOfFileToGivenDirectory) {
48 2 : const std::string Content{"content"};
49 2 : const std::string Name{"ar-stringfile-save-copy-to-test.txt"};
50 2 : StringFile file{Content, Name};
51 :
52 1 : file.saveCopyTo(".");
53 :
54 2 : RemoveFileOnDestruction remover{Name};
55 1 : ASSERT_EQ(Content, readFile(Name));
56 : }
57 :
58 : } // namespace tests
59 : } // namespace internal
60 3 : } // namespace ar
|