Mercurial > hg > orthanc
annotate UnitTests/Zip.cpp @ 524:d80376e73f52
fix of issue #8
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Sep 2013 17:48:00 +0200 |
parents | 4dc9d00c359c |
children |
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 | |
21 TEST(ZipWriter, Exceptions) | |
22 { | |
23 Orthanc::ZipWriter w; | |
24 ASSERT_THROW(w.Open(), Orthanc::OrthancException); | |
25 w.SetOutputPath("hello.zip"); | |
26 w.Open(); | |
27 ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException); | |
28 } | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
29 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
30 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
31 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
32 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
33 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
34 namespace Orthanc |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
35 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
36 // The namespace is necessary |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
37 // 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
|
38 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
39 TEST(HierarchicalZipWriter, Index) |
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 HierarchicalZipWriter::Index i; |
249 | 42 ASSERT_EQ("hello", i.OpenFile("hello")); |
43 ASSERT_EQ("hello-2", i.OpenFile("hello")); | |
44 ASSERT_EQ("coucou", i.OpenFile("coucou")); | |
45 ASSERT_EQ("hello-3", i.OpenFile("hello")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
46 |
249 | 47 i.OpenDirectory("coucou"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
48 |
249 | 49 ASSERT_EQ("coucou-2/world", i.OpenFile("world")); |
50 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
|
51 |
249 | 52 i.OpenDirectory("world"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
53 |
249 | 54 ASSERT_EQ("coucou-2/world-3/hello", i.OpenFile("hello")); |
55 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
|
56 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
57 i.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
58 |
249 | 59 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
|
60 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
61 i.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
62 |
249 | 63 ASSERT_EQ("coucou-3", i.OpenFile("coucou")); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
64 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
65 ASSERT_THROW(i.CloseDirectory(), OrthancException); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
66 } |
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 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
69 TEST(HierarchicalZipWriter, Filenames) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
70 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
71 ASSERT_EQ("trE hell", HierarchicalZipWriter::Index::KeepAlphanumeric(" ÊtrE hellô ")); |
251 | 72 |
73 // The "^" character is considered as a space in DICOM | |
74 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
|
75 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
76 } |
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 TEST(HierarchicalZipWriter, Basic) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
80 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
81 static const std::string SPACES = " "; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
82 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
83 HierarchicalZipWriter w("hello2.zip"); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
84 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
85 w.SetCompressionLevel(0); |
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 // Inside "/" |
249 | 88 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
89 w.Write(SPACES + "hello\n"); |
249 | 90 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
91 w.Write(SPACES + "hello-2\n"); |
249 | 92 w.OpenDirectory("hello"); |
247
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 // Inside "/hello-3" |
249 | 95 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
96 w.Write(SPACES + "hello\n"); |
249 | 97 w.OpenDirectory("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
98 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
99 w.SetCompressionLevel(9); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
100 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
101 // Inside "/hello-3/hello-2" |
249 | 102 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
103 w.Write(SPACES + "hello\n"); |
249 | 104 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
105 w.Write(SPACES + "hello-2\n"); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
106 w.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
107 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
108 // Inside "/hello-3" |
249 | 109 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
110 w.Write(SPACES + "hello-3\n"); |
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 /** |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
113 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
114 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
|
115 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
116 # unzip -v hello2.zip |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
117 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
118 => 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
|
119 compression ratio. |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
120 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
121 **/ |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
122 } |