2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsCSSProps.h"
|
|
|
|
#include "nsCSSKeywords.h"
|
|
|
|
#include "nsString.h"
|
2010-03-02 13:00:39 -08:00
|
|
|
#include "nsXPCOM.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static const char* const kJunkNames[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
"",
|
|
|
|
"123",
|
|
|
|
"backgroundz",
|
|
|
|
"zzzzzz",
|
|
|
|
"#@$&@#*@*$@$#"
|
|
|
|
};
|
|
|
|
|
2010-03-02 13:00:39 -08:00
|
|
|
static bool
|
|
|
|
TestProps()
|
|
|
|
{
|
|
|
|
bool success = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProperty id;
|
|
|
|
nsCSSProperty index;
|
|
|
|
|
|
|
|
// Everything appears to assert if we don't do this first...
|
|
|
|
nsCSSProps::AddRefTable();
|
|
|
|
|
|
|
|
// First make sure we can find all of the tags that are supposed to
|
|
|
|
// be in the table. Futz with the case to make sure any case will
|
|
|
|
// work
|
|
|
|
extern const char* const kCSSRawProperties[];
|
|
|
|
const char*const* et = &kCSSRawProperties[0];
|
|
|
|
const char*const* end = &kCSSRawProperties[eCSSProperty_COUNT];
|
|
|
|
index = eCSSProperty_UNKNOWN;
|
|
|
|
while (et < end) {
|
|
|
|
char tagName[100];
|
|
|
|
PL_strcpy(tagName, *et);
|
2012-08-22 08:56:38 -07:00
|
|
|
index = nsCSSProperty(int32_t(index) + 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-07 09:14:23 -08:00
|
|
|
id = nsCSSProps::LookupProperty(nsCString(tagName),
|
|
|
|
nsCSSProps::eIgnoreEnabledState);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (id == eCSSProperty_UNKNOWN) {
|
|
|
|
printf("bug: can't find '%s'\n", tagName);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (id != index) {
|
|
|
|
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// fiddle with the case to make sure we can still find it
|
|
|
|
if (('a' <= tagName[0]) && (tagName[0] <= 'z')) {
|
|
|
|
tagName[0] = tagName[0] - 32;
|
|
|
|
}
|
2012-07-13 16:59:05 -07:00
|
|
|
id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName),
|
2014-03-07 09:14:23 -08:00
|
|
|
nsCSSProps::eIgnoreEnabledState);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (id < 0) {
|
|
|
|
printf("bug: can't find '%s'\n", tagName);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (index != id) {
|
|
|
|
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
et++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure we don't find some garbage
|
|
|
|
for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
|
|
|
|
const char* const tag = kJunkNames[i];
|
2014-03-07 09:14:23 -08:00
|
|
|
id = nsCSSProps::LookupProperty(nsAutoCString(tag),
|
|
|
|
nsCSSProps::eIgnoreEnabledState);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (id >= 0) {
|
|
|
|
printf("bug: found '%s'\n", tag ? tag : "(null)");
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSProps::ReleaseTable();
|
2010-03-02 13:00:39 -08:00
|
|
|
return success;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-02 13:00:39 -08:00
|
|
|
bool
|
|
|
|
TestKeywords()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSKeywords::AddRefTable();
|
|
|
|
|
2010-03-02 13:00:39 -08:00
|
|
|
bool success = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSKeyword id;
|
|
|
|
nsCSSKeyword index;
|
|
|
|
|
|
|
|
extern const char* const kCSSRawKeywords[];
|
|
|
|
|
|
|
|
// First make sure we can find all of the tags that are supposed to
|
|
|
|
// be in the table. Futz with the case to make sure any case will
|
|
|
|
// work
|
|
|
|
const char*const* et = &kCSSRawKeywords[0];
|
|
|
|
const char*const* end = &kCSSRawKeywords[eCSSKeyword_COUNT - 1];
|
|
|
|
index = eCSSKeyword_UNKNOWN;
|
|
|
|
while (et < end) {
|
|
|
|
char tagName[512];
|
|
|
|
char* underscore = &(tagName[0]);
|
|
|
|
|
|
|
|
PL_strcpy(tagName, *et);
|
|
|
|
while (*underscore) {
|
|
|
|
if (*underscore == '_') {
|
|
|
|
*underscore = '-';
|
|
|
|
}
|
|
|
|
underscore++;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
index = nsCSSKeyword(int32_t(index) + 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
|
|
|
|
if (id <= eCSSKeyword_UNKNOWN) {
|
|
|
|
printf("bug: can't find '%s'\n", tagName);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (id != index) {
|
|
|
|
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// fiddle with the case to make sure we can still find it
|
|
|
|
if (('a' <= tagName[0]) && (tagName[0] <= 'z')) {
|
|
|
|
tagName[0] = tagName[0] - 32;
|
|
|
|
}
|
|
|
|
id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
|
|
|
|
if (id <= eCSSKeyword_UNKNOWN) {
|
|
|
|
printf("bug: can't find '%s'\n", tagName);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (id != index) {
|
|
|
|
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
et++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure we don't find some garbage
|
|
|
|
for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
|
|
|
|
const char* const tag = kJunkNames[i];
|
2012-09-01 19:35:17 -07:00
|
|
|
id = nsCSSKeywords::LookupKeyword(nsAutoCString(tag));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSKeyword_UNKNOWN < id) {
|
|
|
|
printf("bug: found '%s'\n", tag ? tag : "(null)");
|
2010-03-02 13:00:39 -08:00
|
|
|
success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSKeywords::ReleaseTable();
|
2010-03-02 13:00:39 -08:00
|
|
|
return success;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-02 13:00:39 -08:00
|
|
|
int
|
|
|
|
main(void)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
2010-03-02 13:00:39 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, 2);
|
|
|
|
|
|
|
|
bool testOK = true;
|
|
|
|
testOK &= TestProps();
|
|
|
|
testOK &= TestKeywords();
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = NS_ShutdownXPCOM(nullptr);
|
2010-03-02 13:00:39 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, 2);
|
|
|
|
|
|
|
|
return testOK ? 0 : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|