comparison UnitTestsSources/main.cpp @ 707:203157cb4fde

unit tests of httpclient
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Feb 2014 14:37:35 +0100
parents d76b747aec1b
children 38e2883e096f
comparison
equal deleted inserted replaced
706:2d829ea1db96 707:203157cb4fde
29 TEST(Uuid, Test) 29 TEST(Uuid, Test)
30 { 30 {
31 ASSERT_FALSE(Toolbox::IsUuid("")); 31 ASSERT_FALSE(Toolbox::IsUuid(""));
32 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345")); 32 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345"));
33 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000")); 33 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000"));
34 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_"));
34 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000")); 35 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000"));
35 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000")); 36 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000"));
36 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok")); 37 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok"));
37 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok")); 38 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok"));
38 } 39 }
46 47
47 std::string s; 48 std::string s;
48 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); 49 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog");
49 ASSERT_TRUE(Toolbox::IsSHA1(s)); 50 ASSERT_TRUE(Toolbox::IsSHA1(s));
50 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); 51 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
52
53 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_"));
51 } 54 }
52 55
53 TEST(Zlib, Basic) 56 TEST(Zlib, Basic)
54 { 57 {
55 std::string s = Toolbox::GenerateUuid(); 58 std::string s = Toolbox::GenerateUuid();
168 ASSERT_EQ("hello", c[0]); 171 ASSERT_EQ("hello", c[0]);
169 172
170 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException); 173 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException);
171 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException); 174 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException);
172 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException); 175 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException);
176
177 c.clear();
178 c.push_back("test");
179 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10));
173 } 180 }
174 181
175 182
176 TEST(Uri, Child) 183 TEST(Uri, Child)
177 { 184 {
261 268
262 TEST(Toolbox, Base64) 269 TEST(Toolbox, Base64)
263 { 270 {
264 ASSERT_EQ("", Toolbox::EncodeBase64("")); 271 ASSERT_EQ("", Toolbox::EncodeBase64(""));
265 ASSERT_EQ("YQ==", Toolbox::EncodeBase64("a")); 272 ASSERT_EQ("YQ==", Toolbox::EncodeBase64("a"));
266 ASSERT_EQ("SGVsbG8gd29ybGQ=", Toolbox::EncodeBase64("Hello world")); 273
274 const std::string hello = "SGVsbG8gd29ybGQ=";
275 ASSERT_EQ(hello, Toolbox::EncodeBase64("Hello world"));
276 ASSERT_EQ("Hello world", Toolbox::DecodeBase64(hello));
267 } 277 }
268 278
269 TEST(Toolbox, PathToExecutable) 279 TEST(Toolbox, PathToExecutable)
270 { 280 {
271 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str()); 281 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str());
276 { 286 {
277 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n ")); 287 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n "));
278 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n ")); 288 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n "));
279 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n ")); 289 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n "));
280 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n ")); 290 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n "));
291 }
292
293 TEST(Toolbox, Case)
294 {
295 std::string s = "CoU";
296 std::string ss;
297
298 Toolbox::ToUpperCase(ss, s);
299 ASSERT_EQ("COU", ss);
300 Toolbox::ToLowerCase(ss, s);
301 ASSERT_EQ("cou", ss);
302
303 s = "CoU";
304 Toolbox::ToUpperCase(s);
305 ASSERT_EQ("COU", s);
306
307 s = "CoU";
308 Toolbox::ToLowerCase(s);
309 ASSERT_EQ("cou", s);
281 } 310 }
282 311
283 312
284 #include <glog/logging.h> 313 #include <glog/logging.h>
285 314