comparison UnitTestsSources/Zip.cpp @ 632:17815b9d4280

rename the UnitTests directory to avoid clashes in filenames
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 Oct 2013 16:26:51 +0100
parents UnitTests/Zip.cpp@4dc9d00c359c
children eb5a0b21d05e
comparison
equal deleted inserted replaced
631:fc6ad5b97219 632:17815b9d4280
1 #include "gtest/gtest.h"
2
3 #include "../Core/OrthancException.h"
4 #include "../Core/Compression/ZipWriter.h"
5 #include "../Core/Compression/HierarchicalZipWriter.h"
6 #include "../Core/Toolbox.h"
7
8
9 using namespace Orthanc;
10
11 TEST(ZipWriter, Basic)
12 {
13 Orthanc::ZipWriter w;
14 w.SetOutputPath("hello.zip");
15 w.Open();
16 w.OpenFile("world/hello");
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 }
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.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"));
46
47 i.OpenDirectory("coucou");
48
49 ASSERT_EQ("coucou-2/world", i.OpenFile("world"));
50 ASSERT_EQ("coucou-2/world-2", i.OpenFile("world"));
51
52 i.OpenDirectory("world");
53
54 ASSERT_EQ("coucou-2/world-3/hello", i.OpenFile("hello"));
55 ASSERT_EQ("coucou-2/world-3/hello-2", i.OpenFile("hello"));
56
57 i.CloseDirectory();
58
59 ASSERT_EQ("coucou-2/world-4", i.OpenFile("world"));
60
61 i.CloseDirectory();
62
63 ASSERT_EQ("coucou-3", i.OpenFile("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
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> "));
75 }
76 }
77
78
79 TEST(HierarchicalZipWriter, Basic)
80 {
81 static const std::string SPACES = " ";
82
83 HierarchicalZipWriter w("hello2.zip");
84
85 w.SetCompressionLevel(0);
86
87 // Inside "/"
88 w.OpenFile("hello");
89 w.Write(SPACES + "hello\n");
90 w.OpenFile("hello");
91 w.Write(SPACES + "hello-2\n");
92 w.OpenDirectory("hello");
93
94 // Inside "/hello-3"
95 w.OpenFile("hello");
96 w.Write(SPACES + "hello\n");
97 w.OpenDirectory("hello");
98
99 w.SetCompressionLevel(9);
100
101 // Inside "/hello-3/hello-2"
102 w.OpenFile("hello");
103 w.Write(SPACES + "hello\n");
104 w.OpenFile("hello");
105 w.Write(SPACES + "hello-2\n");
106 w.CloseDirectory();
107
108 // Inside "/hello-3"
109 w.OpenFile("hello");
110 w.Write(SPACES + "hello-3\n");
111
112 /**
113
114 TO CHECK THE CONTENT OF THE "hello2.zip" FILE:
115
116 # unzip -v hello2.zip
117
118 => There must be 6 files. The first 3 files must have a negative
119 compression ratio.
120
121 **/
122 }