TestCachePrefixKeyParser.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "TestHarness.h"
  6. #include "nsILoadContextInfo.h"
  7. #include "../cache2/CacheFileUtils.h"
  8. int
  9. main(int32_t argc, char *argv[])
  10. {
  11. nsCOMPtr<nsILoadContextInfo> info;
  12. nsAutoCString key, enh;
  13. #define CHECK(a) MOZ_ASSERT(a)
  14. info = ParseKey(NS_LITERAL_CSTRING(""));
  15. CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
  16. info = ParseKey(NS_LITERAL_CSTRING(":"));
  17. CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
  18. info = ParseKey(NS_LITERAL_CSTRING("a,"));
  19. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
  20. info = ParseKey(NS_LITERAL_CSTRING("a,:"));
  21. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
  22. info = ParseKey(NS_LITERAL_CSTRING("a,:xxx"), &enh, &key);
  23. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
  24. CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
  25. info = ParseKey(NS_LITERAL_CSTRING("b,:xxx"));
  26. CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0);
  27. info = ParseKey(NS_LITERAL_CSTRING("a,b,:xxx"), &enh, &key);
  28. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0);
  29. CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
  30. CHECK(enh.IsEmpty());
  31. info = ParseKey(NS_LITERAL_CSTRING("a,b,i123,:xxx"));
  32. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
  33. info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,:xxx"), &enh, &key);
  34. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
  35. CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
  36. info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,~enh,:xxx"), &enh, &key);
  37. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
  38. CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
  39. CHECK(NS_LITERAL_CSTRING("enh").Equals(enh));
  40. info = ParseKey(NS_LITERAL_CSTRING("0x,1,a,b,i123,:xxx"));
  41. CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
  42. nsAutoCString test;
  43. AppendTagWithValue(test, '~', NS_LITERAL_CSTRING("e,nh,"));
  44. info = ParseKey(test, &enh, &key);
  45. CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
  46. CHECK(NS_LITERAL_CSTRING("e,nh,").Equals(enh));
  47. info = ParseKey(NS_LITERAL_CSTRING("a,i123,b,:xxx"));
  48. CHECK(!info);
  49. info = ParseKey(NS_LITERAL_CSTRING("a"));
  50. CHECK(!info);
  51. info = ParseKey(NS_LITERAL_CSTRING("a:"));
  52. CHECK(!info);
  53. info = ParseKey(NS_LITERAL_CSTRING("a:xxx"));
  54. CHECK(!info);
  55. info = ParseKey(NS_LITERAL_CSTRING("i123"));
  56. CHECK(!info);
  57. info = ParseKey(NS_LITERAL_CSTRING("i123:"));
  58. CHECK(!info);
  59. info = ParseKey(NS_LITERAL_CSTRING("i123:xxx"));
  60. CHECK(!info);
  61. info = ParseKey(NS_LITERAL_CSTRING("i123,x:"));
  62. CHECK(!info);
  63. info = ParseKey(NS_LITERAL_CSTRING("i,x,:"));
  64. CHECK(!info);
  65. info = ParseKey(NS_LITERAL_CSTRING("i:"));
  66. CHECK(!info);
  67. #undef CHECK
  68. passed("ok");
  69. return 0;
  70. }