michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "TestHarness.h" michael@0: #include "nsILoadContextInfo.h" michael@0: #include "../cache2/CacheFileUtils.h" michael@0: michael@0: int michael@0: main(int32_t argc, char *argv[]) michael@0: { michael@0: nsCOMPtr info; michael@0: nsAutoCString key, enh; michael@0: michael@0: #define CHECK(a) MOZ_ASSERT(a) michael@0: michael@0: info = ParseKey(NS_LITERAL_CSTRING("")); michael@0: CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); michael@0: info = ParseKey(NS_LITERAL_CSTRING(":")); michael@0: CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,")); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,:")); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,:xxx"), &enh, &key); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); michael@0: CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); michael@0: info = ParseKey(NS_LITERAL_CSTRING("b,:xxx")); michael@0: CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,b,:xxx"), &enh, &key); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0); michael@0: CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); michael@0: CHECK(enh.IsEmpty()); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,b,i123,:xxx")); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,:xxx"), &enh, &key); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); michael@0: CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,~enh,:xxx"), &enh, &key); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); michael@0: CHECK(NS_LITERAL_CSTRING("xxx").Equals(key)); michael@0: CHECK(NS_LITERAL_CSTRING("enh").Equals(enh)); michael@0: info = ParseKey(NS_LITERAL_CSTRING("0x,1,a,b,i123,:xxx")); michael@0: CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123); michael@0: michael@0: nsAutoCString test; michael@0: AppendTagWithValue(test, '~', NS_LITERAL_CSTRING("e,nh,")); michael@0: info = ParseKey(test, &enh, &key); michael@0: CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0); michael@0: CHECK(NS_LITERAL_CSTRING("e,nh,").Equals(enh)); michael@0: michael@0: info = ParseKey(NS_LITERAL_CSTRING("a,i123,b,:xxx")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a:")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("a:xxx")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("i123")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("i123:")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("i123:xxx")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("i123,x:")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("i,x,:")); michael@0: CHECK(!info); michael@0: info = ParseKey(NS_LITERAL_CSTRING("i:")); michael@0: CHECK(!info); michael@0: michael@0: #undef CHECK michael@0: michael@0: passed("ok"); michael@0: return 0; michael@0: }