source: branches/work_304/util/UntarStreamTest.cpp @ 328

Revision 328, 3.9 KB checked in by jls17, 6 years ago (diff)
Line 
1#include "ARInsideTest.h"
2#include "UntarStream.h"
3#include "UntarStreamTest.h"
4#include "../gzstream.h"
5
6TEST(UntarStreamTests, DISABLED_CodeGenerator)
7{
8        ifstream input("E:\\Programm\\work\\arinside\\test\\test.tar", ios_base::in | ios_base::binary);
9
10        int curLineWidth = 0;   
11        int c = 0;
12
13        while (input)
14        {
15                if (curLineWidth > 120)
16                {
17                        cout << endl;
18                        curLineWidth = 0;
19                }
20
21                input.read(reinterpret_cast<char*>(&c), 1);
22                cout << "0x" << hex << setw(2) << setfill('0') << int(c) << ", ";
23               
24                curLineWidth += 6;
25        }
26}
27
28TEST(UntarStreamTests, ExtractTest)
29{
30        fixed_size_memory_buf buf(test_tar_file_content, sizeof test_tar_file_content);
31        istream input(&buf);
32
33        UntarStreamToMemory untar(input);
34        untar.ExtractAllTo("memory");
35
36#ifdef WIN32
37        ASSERT_EQ(1, untar.dirNames.size());
38        ASSERT_STREQ("memory\\test/", untar.dirNames[0].c_str());
39
40        ASSERT_EQ(2, untar.fileNames.size());
41        ASSERT_STREQ("memory\\test/file1.txt", untar.fileNames[0].c_str());
42        ASSERT_STREQ("memory\\test/file2.txt", untar.fileNames[1].c_str());
43
44        ASSERT_EQ(2, untar.fileContent.size());
45        ASSERT_STREQ("Content of file 1", untar.fileContent[0].c_str());
46        ASSERT_STREQ("Content of file 2\n", untar.fileContent[1].c_str());
47#else
48        ASSERT_EQ(1, untar.dirNames.size());
49        ASSERT_STREQ("memory/test/", untar.dirNames[0].c_str());
50
51        ASSERT_EQ(2, untar.fileNames.size());
52        ASSERT_STREQ("memory/test/file1.txt", untar.fileNames[0].c_str());
53        ASSERT_STREQ("memory/test/file2.txt", untar.fileNames[1].c_str());
54
55        ASSERT_EQ(2, untar.fileContent.size());
56        ASSERT_STREQ("Content of file 1", untar.fileContent[0].c_str());
57        ASSERT_STREQ("Content of file 2\n", untar.fileContent[1].c_str());
58#endif
59}
60
61TEST(UntarStreamTests, DISABLED_ExtractFailTest)
62{
63        fixed_size_memory_buf buf(test_tar_file_content, sizeof test_tar_file_content);
64        istream input(&buf);
65
66        UntarStreamToMemory untar(input);
67        untar.theFilesAlreadyExist = true;
68
69        try
70        {
71                untar.ExtractAllTo("memory");
72        }
73        catch (untar_exception &untarEx)
74        {
75                ASSERT_STREQ("writing destination file failed: code=17, File exists", untarEx.what());
76        }
77}
78
79TEST(UntarStreamTests, ExtractFilesystem)
80{
81        fixed_size_memory_buf buf(test_tar_file_content, sizeof test_tar_file_content);
82        istream input(&buf);
83
84        UntarStreamToMemory untar(input);
85        untar.theFilesAlreadyExist = true;
86        untar.ExtractAllTo(".", UntarStream::SKIP);
87}
88
89TEST(UntarExceptionTests, ThrowRead)
90{
91        try
92        {
93                errno = 2; // no such file or directory
94                throw untar_exception(untar_exception::READ);
95        }
96        catch (exception &ex)
97        {
98                ASSERT_STREQ("reading source file failed: code=2, No such file or directory", ex.what());
99        }
100}
101
102TEST(UntarExceptionTests, ThrowRead_Without_errno)
103{
104        try
105        {
106                errno = 0; // set to zero .. might be the default value
107                throw untar_exception(untar_exception::READ);
108        }
109        catch (exception &ex)
110        {
111                ASSERT_STREQ("reading source file failed", ex.what());
112        }
113}
114
115TEST(UntarExceptionTests, ThrowWrite)
116{
117        try
118        {
119                errno = 13; // permission denied
120                throw untar_exception(untar_exception::WRITE);
121        }
122        catch (exception &ex)
123        {
124                ASSERT_STREQ("writing destination file failed: code=13, Permission denied", ex.what());
125        }
126}
127
128TEST(UntarExceptionTests, ThrowWrite_Without_errno)
129{
130        try
131        {
132                errno = 0; // set to zero .. might be the default value
133                throw untar_exception(untar_exception::WRITE);
134        }
135        catch (exception &ex)
136        {
137                ASSERT_STREQ("writing destination file failed", ex.what());
138        }
139}
140
141TEST(UntarExceptionTests, ThrowGeneric)
142{
143        try
144        {
145                errno = 28; // no space left on device
146                throw untar_exception();
147        }
148        catch (exception &ex)
149        {
150                ASSERT_STREQ("generic untar exception: code=28, No space left on device", ex.what());
151        }
152}
153
154TEST(UntarExceptionTests, ThrowGeneric_Without_errno)
155{
156        try
157        {
158                errno = 0; // set to zero .. might be the default value
159                throw untar_exception();
160        }
161        catch (exception &ex)
162        {
163                ASSERT_STREQ("generic untar exception", ex.what());
164        }
165}
166
Note: See TracBrowser for help on using the repository browser.