1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 /* This tests the margin parsing functionality in nsAttrValue.cpp, which
7 * is accessible via nsContentUtils, and is used in setting chromemargins
8 * to widget windows. It's located here due to linking issues in the
12 /* This test no longer compiles now that we've removed nsIContentUtils (bug
13 * 647273). We need to be internal code in order to include nsContentUtils.h,
14 * but defining MOZILLA_INTERNAL_API is not enough to make us internal.
17 #include "TestHarness.h"
19 #ifndef MOZILLA_INTERNAL_API
20 # error This test needs MOZILLA_INTERNAL_API (see bug 652123)
24 #include "nsContentUtils.h"
36 const bool SHOULD_FAIL
= true;
37 const int SHOULD_PASS
= false;
40 {SHOULD_FAIL
, "", 1, 2, 3, 4},
41 {SHOULD_FAIL
, "1,0,0,0", 1, 2, 3, 4},
42 {SHOULD_FAIL
, "1,2,0,0", 1, 2, 3, 4},
43 {SHOULD_FAIL
, "1,2,3,0", 1, 2, 3, 4},
44 {SHOULD_FAIL
, "4,3,2,1", 1, 2, 3, 4},
45 {SHOULD_FAIL
, "azsasdasd", 0, 0, 0, 0},
46 {SHOULD_FAIL
, ",azsasdasd", 0, 0, 0, 0},
47 {SHOULD_FAIL
, " ", 1, 2, 3, 4},
49 "azsdfsdfsdfsdfsdfsasdasd,asdasdasdasdasdasd,asdadasdasd,asdasdasdasd", 0,
51 {SHOULD_FAIL
, "as,as,as,as", 0, 0, 0, 0},
52 {SHOULD_FAIL
, "0,0,0", 0, 0, 0, 0},
53 {SHOULD_FAIL
, "0,0", 0, 0, 0, 0},
54 {SHOULD_FAIL
, "4.6,1,1,1", 0, 0, 0, 0},
55 {SHOULD_FAIL
, ",,,,", 0, 0, 0, 0},
56 {SHOULD_FAIL
, "1, , , ,", 0, 0, 0, 0},
57 {SHOULD_FAIL
, "1, , ,", 0, 0, 0, 0},
58 {SHOULD_FAIL
, "@!@%^&^*()", 1, 2, 3, 4},
59 {SHOULD_PASS
, "4,3,2,1", 4, 3, 2, 1},
60 {SHOULD_PASS
, "-4,-3,-2,-1", -4, -3, -2, -1},
61 {SHOULD_PASS
, "10000,3,2,1", 10000, 3, 2, 1},
62 {SHOULD_PASS
, "4 , 3 , 2 , 1", 4, 3, 2, 1},
63 {SHOULD_PASS
, "4, 3 ,2,1", 4, 3, 2, 1},
64 {SHOULD_FAIL
, "4,3,2,10000000000000 --", 4, 3, 2, 10000000000000},
65 {SHOULD_PASS
, "4,3,2,1000", 4, 3, 2, 1000},
66 {SHOULD_PASS
, "2147483647,3,2,1000", 2147483647, 3, 2, 1000},
67 {SHOULD_PASS
, "2147483647,2147483647,2147483647,2147483647", 2147483647,
68 2147483647, 2147483647, 2147483647},
69 {SHOULD_PASS
, "-2147483647,3,2,1000", -2147483647, 3, 2, 1000},
70 {SHOULD_FAIL
, "2147483648,3,2,1000", 1, 3, 2, 1000},
71 {0, nullptr, 0, 0, 0, 0}};
73 void DoAttrValueTest() {
76 while (Data
[++idx
].margins
) {
78 str
.AssignLiteral(Data
[idx
].margins
);
79 nsIntMargin
values(99, 99, 99, 99);
80 bool result
= nsContentUtils::ParseIntMarginValue(str
, values
);
84 if (Data
[idx
].shouldfail
) continue;
85 fail(Data
[idx
].margins
);
91 if (Data
[idx
].shouldfail
) {
92 if (Data
[idx
].top
== values
.top
&& Data
[idx
].right
== values
.right
&&
93 Data
[idx
].bottom
== values
.bottom
&& Data
[idx
].left
== values
.left
) {
95 fail(Data
[idx
].margins
);
100 // good failure, parse failed and that's what we expected.
104 printf("%d==%d %d==%d %d==%d %d==%d\n",
105 Data
[idx
].top
, values
.top
,
106 Data
[idx
].right
, values
.right
,
107 Data
[idx
].bottom
, values
.bottom
,
108 Data
[idx
].left
, values
.left
);
110 if (Data
[idx
].top
== values
.top
&& Data
[idx
].right
== values
.right
&&
111 Data
[idx
].bottom
== values
.bottom
&& Data
[idx
].left
== values
.left
) {
112 // good parse results
115 fail(Data
[idx
].margins
);
122 if (!didFail
) passed("nsAttrValue margin parsing tests passed.");
125 int main(int argc
, char** argv
) {
126 ScopedXPCOM
xpcom("");
127 if (xpcom
.failed()) return 1;