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 // some of the includes make use of internal string types
21 #define nsAString_h___
23 #define nsStringFwd_h___
24 #define nsReadableUtils_h___
29 class nsAdoptingString
;
30 class nsAdoptingCString
;
32 template<class T
> class nsReadingIterator
;
36 #include "nsContentUtils.h"
38 #ifndef MOZILLA_INTERNAL_API
41 #undef nsReadableUtils_h___
53 const bool SHOULD_FAIL
= true;
54 const int SHOULD_PASS
= false;
57 { SHOULD_FAIL
, "", 1, 2, 3, 4 },
58 { SHOULD_FAIL
, "1,0,0,0", 1, 2, 3, 4 },
59 { SHOULD_FAIL
, "1,2,0,0", 1, 2, 3, 4 },
60 { SHOULD_FAIL
, "1,2,3,0", 1, 2, 3, 4 },
61 { SHOULD_FAIL
, "4,3,2,1", 1, 2, 3, 4 },
62 { SHOULD_FAIL
, "azsasdasd", 0, 0, 0, 0 },
63 { SHOULD_FAIL
, ",azsasdasd", 0, 0, 0, 0 },
64 { SHOULD_FAIL
, " ", 1, 2, 3, 4 },
65 { SHOULD_FAIL
, "azsdfsdfsdfsdfsdfsasdasd,asdasdasdasdasdasd,asdadasdasd,asdasdasdasd", 0, 0, 0, 0 },
66 { SHOULD_FAIL
, "as,as,as,as", 0, 0, 0, 0 },
67 { SHOULD_FAIL
, "0,0,0", 0, 0, 0, 0 },
68 { SHOULD_FAIL
, "0,0", 0, 0, 0, 0 },
69 { SHOULD_FAIL
, "4.6,1,1,1", 0, 0, 0, 0 },
70 { SHOULD_FAIL
, ",,,,", 0, 0, 0, 0 },
71 { SHOULD_FAIL
, "1, , , ,", 0, 0, 0, 0 },
72 { SHOULD_FAIL
, "1, , ,", 0, 0, 0, 0 },
73 { SHOULD_FAIL
, "@!@%^&^*()", 1, 2, 3, 4 },
74 { SHOULD_PASS
, "4,3,2,1", 4, 3, 2, 1 },
75 { SHOULD_PASS
, "-4,-3,-2,-1", -4, -3, -2, -1 },
76 { SHOULD_PASS
, "10000,3,2,1", 10000, 3, 2, 1 },
77 { SHOULD_PASS
, "4 , 3 , 2 , 1", 4, 3, 2, 1 },
78 { SHOULD_PASS
, "4, 3 ,2,1", 4, 3, 2, 1 },
79 { SHOULD_FAIL
, "4,3,2,10000000000000 --", 4, 3, 2, 10000000000000 },
80 { SHOULD_PASS
, "4,3,2,1000", 4, 3, 2, 1000 },
81 { SHOULD_PASS
, "2147483647,3,2,1000", 2147483647, 3, 2, 1000 },
82 { SHOULD_PASS
, "2147483647,2147483647,2147483647,2147483647", 2147483647, 2147483647, 2147483647, 2147483647 },
83 { SHOULD_PASS
, "-2147483647,3,2,1000", -2147483647, 3, 2, 1000 },
84 { SHOULD_FAIL
, "2147483648,3,2,1000", 1, 3, 2, 1000 },
85 { 0, nullptr, 0, 0, 0, 0 }
88 void DoAttrValueTest()
92 while (Data
[++idx
].margins
) {
94 str
.AssignLiteral(Data
[idx
].margins
);
95 nsIntMargin
values(99,99,99,99);
96 bool result
= nsContentUtils::ParseIntMarginValue(str
, values
);
100 if (Data
[idx
].shouldfail
)
102 fail(Data
[idx
].margins
);
108 if (Data
[idx
].shouldfail
) {
109 if (Data
[idx
].top
== values
.top
&&
110 Data
[idx
].right
== values
.right
&&
111 Data
[idx
].bottom
== values
.bottom
&&
112 Data
[idx
].left
== values
.left
) {
114 fail(Data
[idx
].margins
);
119 // good failure, parse failed and that's what we expected.
123 printf("%d==%d %d==%d %d==%d %d==%d\n",
124 Data
[idx
].top
, values
.top
,
125 Data
[idx
].right
, values
.right
,
126 Data
[idx
].bottom
, values
.bottom
,
127 Data
[idx
].left
, values
.left
);
129 if (Data
[idx
].top
== values
.top
&&
130 Data
[idx
].right
== values
.right
&&
131 Data
[idx
].bottom
== values
.bottom
&&
132 Data
[idx
].left
== values
.left
) {
133 // good parse results
137 fail(Data
[idx
].margins
);
145 passed("nsAttrValue margin parsing tests passed.");
148 int main(int argc
, char** argv
)
150 ScopedXPCOM
xpcom("");