Mercurial > hg > orthanc
comparison UnitTests/Zip.cpp @ 247:c9b3ba0fd140
path management in zip files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Dec 2012 17:27:23 +0100 |
parents | 0ec5e2e327b1 |
children | 5694365ecb96 |
comparison
equal
deleted
inserted
replaced
246:fe6ba20d00a8 | 247:c9b3ba0fd140 |
---|---|
1 #include "gtest/gtest.h" | 1 #include "gtest/gtest.h" |
2 | 2 |
3 #include "../Core/OrthancException.h" | 3 #include "../Core/OrthancException.h" |
4 #include "../Core/Compression/ZipWriter.h" | 4 #include "../Core/Compression/ZipWriter.h" |
5 #include "../Core/Compression/HierarchicalZipWriter.h" | |
6 #include "../Core/Toolbox.h" | |
5 | 7 |
8 | |
9 using namespace Orthanc; | |
6 | 10 |
7 TEST(ZipWriter, Basic) | 11 TEST(ZipWriter, Basic) |
8 { | 12 { |
9 Orthanc::ZipWriter w; | 13 Orthanc::ZipWriter w; |
10 w.SetOutputPath("hello.zip"); | 14 w.SetOutputPath("hello.zip"); |
20 ASSERT_THROW(w.Open(), Orthanc::OrthancException); | 24 ASSERT_THROW(w.Open(), Orthanc::OrthancException); |
21 w.SetOutputPath("hello.zip"); | 25 w.SetOutputPath("hello.zip"); |
22 w.Open(); | 26 w.Open(); |
23 ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException); | 27 ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException); |
24 } | 28 } |
29 | |
30 | |
31 | |
32 | |
33 | |
34 namespace Orthanc | |
35 { | |
36 // The namespace is necessary | |
37 // http://code.google.com/p/googletest/wiki/AdvancedGuide#Private_Class_Members | |
38 | |
39 TEST(HierarchicalZipWriter, Index) | |
40 { | |
41 HierarchicalZipWriter::Index i; | |
42 ASSERT_EQ("hello", i.CreateFile("hello")); | |
43 ASSERT_EQ("hello-2", i.CreateFile("hello")); | |
44 ASSERT_EQ("coucou", i.CreateFile("coucou")); | |
45 ASSERT_EQ("hello-3", i.CreateFile("hello")); | |
46 | |
47 i.CreateDirectory("coucou"); | |
48 | |
49 ASSERT_EQ("coucou-2/world", i.CreateFile("world")); | |
50 ASSERT_EQ("coucou-2/world-2", i.CreateFile("world")); | |
51 | |
52 i.CreateDirectory("world"); | |
53 | |
54 ASSERT_EQ("coucou-2/world-3/hello", i.CreateFile("hello")); | |
55 ASSERT_EQ("coucou-2/world-3/hello-2", i.CreateFile("hello")); | |
56 | |
57 i.CloseDirectory(); | |
58 | |
59 ASSERT_EQ("coucou-2/world-4", i.CreateFile("world")); | |
60 | |
61 i.CloseDirectory(); | |
62 | |
63 ASSERT_EQ("coucou-3", i.CreateFile("coucou")); | |
64 | |
65 ASSERT_THROW(i.CloseDirectory(), OrthancException); | |
66 } | |
67 | |
68 | |
69 TEST(HierarchicalZipWriter, Filenames) | |
70 { | |
71 ASSERT_EQ("trE hell", HierarchicalZipWriter::Index::KeepAlphanumeric(" ÊtrE hellô ")); | |
72 ASSERT_EQ("Hello world", HierarchicalZipWriter::Index::KeepAlphanumeric(" Hel^^lo \t <world> ")); | |
73 } | |
74 } | |
75 | |
76 | |
77 TEST(HierarchicalZipWriter, Basic) | |
78 { | |
79 static const std::string SPACES = " "; | |
80 | |
81 HierarchicalZipWriter w("hello2.zip"); | |
82 | |
83 w.SetCompressionLevel(0); | |
84 | |
85 // Inside "/" | |
86 w.CreateFile("hello"); | |
87 w.Write(SPACES + "hello\n"); | |
88 w.CreateFile("hello"); | |
89 w.Write(SPACES + "hello-2\n"); | |
90 w.CreateDirectory("hello"); | |
91 | |
92 // Inside "/hello-3" | |
93 w.CreateFile("hello"); | |
94 w.Write(SPACES + "hello\n"); | |
95 w.CreateDirectory("hello"); | |
96 | |
97 w.SetCompressionLevel(9); | |
98 | |
99 // Inside "/hello-3/hello-2" | |
100 w.CreateFile("hello"); | |
101 w.Write(SPACES + "hello\n"); | |
102 w.CreateFile("hello"); | |
103 w.Write(SPACES + "hello-2\n"); | |
104 w.CloseDirectory(); | |
105 | |
106 // Inside "/hello-3" | |
107 w.CreateFile("hello"); | |
108 w.Write(SPACES + "hello-3\n"); | |
109 | |
110 /** | |
111 | |
112 TO CHECK THE CONTENT OF THE "hello2.zip" FILE: | |
113 | |
114 # unzip -v hello2.zip | |
115 | |
116 => There must be 6 files. The first 3 files must have a negative | |
117 compression ratio. | |
118 | |
119 **/ | |
120 } |