Line data Source code
1 : ///
2 : /// @file ar/extraction_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 extraction module.
6 : ///
7 :
8 : #include <gtest/gtest.h>
9 :
10 : #include "ar/exceptions.h"
11 : #include "ar/extraction.h"
12 : #include "ar/file.h"
13 :
14 : namespace ar {
15 : namespace tests {
16 :
17 : ///
18 : /// Tests for extract().
19 : ///
20 6 : class ExtractTests: public testing::Test {};
21 :
22 5 : TEST_F(ExtractTests,
23 : ExtractReturnsEmptyContainerForEmptyArchive) {
24 : auto files = extract(
25 2 : File::fromContentWithName("!<arch>\n", "archive.a")
26 2 : );
27 :
28 1 : ASSERT_TRUE(files.empty());
29 : }
30 :
31 5 : TEST_F(ExtractTests,
32 : ExtractReturnsSingletonContainerForArchiveWithSingleFile) {
33 : auto files = extract(
34 2 : File::fromContentWithName(
35 : "!<arch>\n"
36 : "test.txt/ 0 0 0 644 20 `\n"
37 : "contents of test.txt"
38 : ,
39 : "archive.a"
40 : )
41 2 : );
42 :
43 1 : ASSERT_EQ(1, files.size());
44 1 : auto& file = files.front();
45 1 : ASSERT_EQ("test.txt", file->getName());
46 1 : ASSERT_EQ("contents of test.txt", file->getContent());
47 : }
48 :
49 5 : TEST_F(ExtractTests,
50 : ExtractThrowsInvalidArchiveErrorWhenMagicStringIsNotPresent) {
51 2 : ASSERT_THROW(
52 : extract(File::fromContentWithName("", "archive.a")),
53 : InvalidArchiveError
54 1 : );
55 : }
56 :
57 : } // namespace tests
58 3 : } // namespace ar
|