Mercurial > hg > orthanc
annotate UnitTestsSources/Zip.cpp @ 794:437c4a83d2cc
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 May 2014 10:52:20 +0200 |
parents | eb5a0b21d05e |
children | 4689e400e0fa |
rev | line source |
---|---|
81 | 1 #include "gtest/gtest.h" |
2 | |
3 #include "../Core/OrthancException.h" | |
4 #include "../Core/Compression/ZipWriter.h" | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
5 #include "../Core/Compression/HierarchicalZipWriter.h" |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
6 #include "../Core/Toolbox.h" |
81 | 7 |
8 | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
9 using namespace Orthanc; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
10 |
81 | 11 TEST(ZipWriter, Basic) |
12 { | |
13 Orthanc::ZipWriter w; | |
14 w.SetOutputPath("hello.zip"); | |
15 w.Open(); | |
249 | 16 w.OpenFile("world/hello"); |
81 | 17 w.Write("Hello world"); |
18 } | |
19 | |
20 | |
644
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
21 TEST(ZipWriter, Basic64) |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
22 { |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
23 Orthanc::ZipWriter w; |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
24 w.SetOutputPath("hello64.zip"); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
25 w.SetZip64(true); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
26 w.Open(); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
27 w.OpenFile("world/hello"); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
28 w.Write("Hello world"); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
29 } |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
30 |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
31 |
81 | 32 TEST(ZipWriter, Exceptions) |
33 { | |
34 Orthanc::ZipWriter w; | |
35 ASSERT_THROW(w.Open(), Orthanc::OrthancException); | |
644
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
36 w.SetOutputPath("hello3.zip"); |
81 | 37 w.Open(); |
38 ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException); | |
39 } | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
40 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
41 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
42 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
43 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
44 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
45 namespace Orthanc |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
46 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
47 // The namespace is necessary |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
48 // http://code.google.com/p/googletest/wiki/AdvancedGuide#Private_Class_Members |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
49 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
50 TEST(HierarchicalZipWriter, Index) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
51 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
52 HierarchicalZipWriter::Index i; |
249 | 53 ASSERT_EQ("hello", i.OpenFile("hello")); |
54 ASSERT_EQ("hello-2", i.OpenFile("hello")); | |
55 ASSERT_EQ("coucou", i.OpenFile("coucou")); | |
56 ASSERT_EQ("hello-3", i.OpenFile("hello")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
57 |
249 | 58 i.OpenDirectory("coucou"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
59 |
249 | 60 ASSERT_EQ("coucou-2/world", i.OpenFile("world")); |
61 ASSERT_EQ("coucou-2/world-2", i.OpenFile("world")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
62 |
249 | 63 i.OpenDirectory("world"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
64 |
249 | 65 ASSERT_EQ("coucou-2/world-3/hello", i.OpenFile("hello")); |
66 ASSERT_EQ("coucou-2/world-3/hello-2", i.OpenFile("hello")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
67 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
68 i.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
69 |
249 | 70 ASSERT_EQ("coucou-2/world-4", i.OpenFile("world")); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
71 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
72 i.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
73 |
249 | 74 ASSERT_EQ("coucou-3", i.OpenFile("coucou")); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
75 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
76 ASSERT_THROW(i.CloseDirectory(), OrthancException); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
77 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
78 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
79 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
80 TEST(HierarchicalZipWriter, Filenames) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
81 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
82 ASSERT_EQ("trE hell", HierarchicalZipWriter::Index::KeepAlphanumeric(" ÊtrE hellô ")); |
251 | 83 |
84 // The "^" character is considered as a space in DICOM | |
85 ASSERT_EQ("Hel lo world", HierarchicalZipWriter::Index::KeepAlphanumeric(" Hel^^ ^\r\n\t^^lo \t <world> ")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
86 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
87 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
88 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
89 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
90 TEST(HierarchicalZipWriter, Basic) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
91 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
92 static const std::string SPACES = " "; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
93 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
94 HierarchicalZipWriter w("hello2.zip"); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
95 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
96 w.SetCompressionLevel(0); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
97 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
98 // Inside "/" |
249 | 99 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
100 w.Write(SPACES + "hello\n"); |
249 | 101 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
102 w.Write(SPACES + "hello-2\n"); |
249 | 103 w.OpenDirectory("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
104 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
105 // Inside "/hello-3" |
249 | 106 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
107 w.Write(SPACES + "hello\n"); |
249 | 108 w.OpenDirectory("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
109 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
110 w.SetCompressionLevel(9); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
111 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
112 // Inside "/hello-3/hello-2" |
249 | 113 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
114 w.Write(SPACES + "hello\n"); |
249 | 115 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
116 w.Write(SPACES + "hello-2\n"); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
117 w.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
118 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
119 // Inside "/hello-3" |
249 | 120 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
121 w.Write(SPACES + "hello-3\n"); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
122 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
123 /** |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
124 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
125 TO CHECK THE CONTENT OF THE "hello2.zip" FILE: |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
126 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
127 # unzip -v hello2.zip |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
128 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
129 => There must be 6 files. The first 3 files must have a negative |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
130 compression ratio. |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
131 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
132 **/ |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
133 } |