michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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: #include michael@0: #include "plstr.h" michael@0: #include "nsCSSProps.h" michael@0: #include "nsCSSKeywords.h" michael@0: #include "nsString.h" michael@0: #include "nsXPCOM.h" michael@0: michael@0: static const char* const kJunkNames[] = { michael@0: nullptr, michael@0: "", michael@0: "123", michael@0: "backgroundz", michael@0: "zzzzzz", michael@0: "#@$&@#*@*$@$#" michael@0: }; michael@0: michael@0: static bool michael@0: TestProps() michael@0: { michael@0: bool success = true; michael@0: nsCSSProperty id; michael@0: nsCSSProperty index; michael@0: michael@0: // Everything appears to assert if we don't do this first... michael@0: nsCSSProps::AddRefTable(); michael@0: michael@0: // First make sure we can find all of the tags that are supposed to michael@0: // be in the table. Futz with the case to make sure any case will michael@0: // work michael@0: extern const char* const kCSSRawProperties[]; michael@0: const char*const* et = &kCSSRawProperties[0]; michael@0: const char*const* end = &kCSSRawProperties[eCSSProperty_COUNT]; michael@0: index = eCSSProperty_UNKNOWN; michael@0: while (et < end) { michael@0: char tagName[100]; michael@0: PL_strcpy(tagName, *et); michael@0: index = nsCSSProperty(int32_t(index) + 1); michael@0: michael@0: id = nsCSSProps::LookupProperty(nsCString(tagName), michael@0: nsCSSProps::eIgnoreEnabledState); michael@0: if (id == eCSSProperty_UNKNOWN) { michael@0: printf("bug: can't find '%s'\n", tagName); michael@0: success = false; michael@0: } michael@0: if (id != index) { michael@0: printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); michael@0: success = false; michael@0: } michael@0: michael@0: // fiddle with the case to make sure we can still find it michael@0: if (('a' <= tagName[0]) && (tagName[0] <= 'z')) { michael@0: tagName[0] = tagName[0] - 32; michael@0: } michael@0: id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName), michael@0: nsCSSProps::eIgnoreEnabledState); michael@0: if (id < 0) { michael@0: printf("bug: can't find '%s'\n", tagName); michael@0: success = false; michael@0: } michael@0: if (index != id) { michael@0: printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); michael@0: success = false; michael@0: } michael@0: et++; michael@0: } michael@0: michael@0: // Now make sure we don't find some garbage michael@0: for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) { michael@0: const char* const tag = kJunkNames[i]; michael@0: id = nsCSSProps::LookupProperty(nsAutoCString(tag), michael@0: nsCSSProps::eIgnoreEnabledState); michael@0: if (id >= 0) { michael@0: printf("bug: found '%s'\n", tag ? tag : "(null)"); michael@0: success = false; michael@0: } michael@0: } michael@0: michael@0: nsCSSProps::ReleaseTable(); michael@0: return success; michael@0: } michael@0: michael@0: bool michael@0: TestKeywords() michael@0: { michael@0: nsCSSKeywords::AddRefTable(); michael@0: michael@0: bool success = true; michael@0: nsCSSKeyword id; michael@0: nsCSSKeyword index; michael@0: michael@0: extern const char* const kCSSRawKeywords[]; michael@0: michael@0: // First make sure we can find all of the tags that are supposed to michael@0: // be in the table. Futz with the case to make sure any case will michael@0: // work michael@0: const char*const* et = &kCSSRawKeywords[0]; michael@0: const char*const* end = &kCSSRawKeywords[eCSSKeyword_COUNT - 1]; michael@0: index = eCSSKeyword_UNKNOWN; michael@0: while (et < end) { michael@0: char tagName[512]; michael@0: char* underscore = &(tagName[0]); michael@0: michael@0: PL_strcpy(tagName, *et); michael@0: while (*underscore) { michael@0: if (*underscore == '_') { michael@0: *underscore = '-'; michael@0: } michael@0: underscore++; michael@0: } michael@0: index = nsCSSKeyword(int32_t(index) + 1); michael@0: michael@0: id = nsCSSKeywords::LookupKeyword(nsCString(tagName)); michael@0: if (id <= eCSSKeyword_UNKNOWN) { michael@0: printf("bug: can't find '%s'\n", tagName); michael@0: success = false; michael@0: } michael@0: if (id != index) { michael@0: printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); michael@0: success = false; michael@0: } michael@0: michael@0: // fiddle with the case to make sure we can still find it michael@0: if (('a' <= tagName[0]) && (tagName[0] <= 'z')) { michael@0: tagName[0] = tagName[0] - 32; michael@0: } michael@0: id = nsCSSKeywords::LookupKeyword(nsCString(tagName)); michael@0: if (id <= eCSSKeyword_UNKNOWN) { michael@0: printf("bug: can't find '%s'\n", tagName); michael@0: success = false; michael@0: } michael@0: if (id != index) { michael@0: printf("bug: name='%s' id=%d index=%d\n", tagName, id, index); michael@0: success = false; michael@0: } michael@0: et++; michael@0: } michael@0: michael@0: // Now make sure we don't find some garbage michael@0: for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) { michael@0: const char* const tag = kJunkNames[i]; michael@0: id = nsCSSKeywords::LookupKeyword(nsAutoCString(tag)); michael@0: if (eCSSKeyword_UNKNOWN < id) { michael@0: printf("bug: found '%s'\n", tag ? tag : "(null)"); michael@0: success = false; michael@0: } michael@0: } michael@0: michael@0: nsCSSKeywords::ReleaseTable(); michael@0: return success; michael@0: } michael@0: michael@0: int michael@0: main(void) michael@0: { michael@0: nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); michael@0: NS_ENSURE_SUCCESS(rv, 2); michael@0: michael@0: bool testOK = true; michael@0: testOK &= TestProps(); michael@0: testOK &= TestKeywords(); michael@0: michael@0: rv = NS_ShutdownXPCOM(nullptr); michael@0: NS_ENSURE_SUCCESS(rv, 2); michael@0: michael@0: return testOK ? 0 : 1; michael@0: }