/src/mozilla-central/dom/base/test/gtest/TestXPathGenerator.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "gtest/gtest.h" |
8 | | #include "XPathGenerator.h" |
9 | | #include "nsString.h" |
10 | | |
11 | | TEST(TestXPathGenerator, TestQuoteArgumentWithoutQuote) |
12 | 0 | { |
13 | 0 | nsAutoString arg; |
14 | 0 | arg.AssignLiteral(u"testing"); |
15 | 0 |
|
16 | 0 | nsAutoString expectedResult; |
17 | 0 | expectedResult.AssignLiteral(u"\'testing\'"); |
18 | 0 |
|
19 | 0 | nsAutoString result; |
20 | 0 | XPathGenerator::QuoteArgument(arg, result); |
21 | 0 |
|
22 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
23 | 0 | } |
24 | | |
25 | | TEST(TestXPathGenerator, TestQuoteArgumentWithSingleQuote) |
26 | 0 | { |
27 | 0 | nsAutoString arg; |
28 | 0 | arg.AssignLiteral(u"\'testing\'"); |
29 | 0 |
|
30 | 0 | nsAutoString expectedResult; |
31 | 0 | expectedResult.AssignLiteral(u"\"\'testing\'\""); |
32 | 0 |
|
33 | 0 | nsAutoString result; |
34 | 0 | XPathGenerator::QuoteArgument(arg, result); |
35 | 0 |
|
36 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
37 | 0 | } |
38 | | |
39 | | TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuote) |
40 | 0 | { |
41 | 0 | nsAutoString arg; |
42 | 0 | arg.AssignLiteral(u"\"testing\""); |
43 | 0 |
|
44 | 0 | nsAutoString expectedResult; |
45 | 0 | expectedResult.AssignLiteral(u"\'\"testing\"\'"); |
46 | 0 |
|
47 | 0 | nsAutoString result; |
48 | 0 | XPathGenerator::QuoteArgument(arg, result); |
49 | 0 |
|
50 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
51 | 0 | } |
52 | | |
53 | | TEST(TestXPathGenerator, TestQuoteArgumentWithSingleAndDoubleQuote) |
54 | 0 | { |
55 | 0 | nsAutoString arg; |
56 | 0 | arg.AssignLiteral(u"\'testing\""); |
57 | 0 |
|
58 | 0 | nsAutoString expectedResult; |
59 | 0 | expectedResult.AssignLiteral(u"concat(\'\',\"\'\",\'testing\"\')"); |
60 | 0 |
|
61 | 0 | nsAutoString result; |
62 | 0 | XPathGenerator::QuoteArgument(arg, result); |
63 | 0 | printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); |
64 | 0 |
|
65 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
66 | 0 | } |
67 | | |
68 | | TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndASequenceOfSingleQuote) |
69 | 0 | { |
70 | 0 | nsAutoString arg; |
71 | 0 | arg.AssignLiteral(u"\'\'\'\'testing\""); |
72 | 0 |
|
73 | 0 | nsAutoString expectedResult; |
74 | 0 | expectedResult.AssignLiteral(u"concat(\'\',\"\'\'\'\'\",\'testing\"\')"); |
75 | 0 |
|
76 | 0 | nsAutoString result; |
77 | 0 | XPathGenerator::QuoteArgument(arg, result); |
78 | 0 | printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); |
79 | 0 |
|
80 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
81 | 0 | } |
82 | | |
83 | | TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuote) |
84 | 0 | { |
85 | 0 | nsAutoString arg; |
86 | 0 | arg.AssignLiteral(u"\'\'\'\'testing\'\'\'\'\'\'\""); |
87 | 0 |
|
88 | 0 | nsAutoString expectedResult; |
89 | 0 | expectedResult.AssignLiteral(u"concat(\'\',\"\'\'\'\'\",\'testing\',\"\'\'\'\'\'\'\",\'\"\')"); |
90 | 0 |
|
91 | 0 | nsAutoString result; |
92 | 0 | XPathGenerator::QuoteArgument(arg, result); |
93 | 0 | printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); |
94 | 0 |
|
95 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
96 | 0 | } |
97 | | |
98 | | TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuoteInMiddle) |
99 | 0 | { |
100 | 0 | nsAutoString arg; |
101 | 0 | arg.AssignLiteral(u"t\'\'\'\'estin\'\'\'\'\'\'\"g"); |
102 | 0 |
|
103 | 0 | nsAutoString expectedResult; |
104 | 0 | expectedResult.AssignLiteral(u"concat(\'t\',\"\'\'\'\'\",\'estin\',\"\'\'\'\'\'\'\",\'\"g\')"); |
105 | 0 |
|
106 | 0 | nsAutoString result; |
107 | 0 | XPathGenerator::QuoteArgument(arg, result); |
108 | 0 | printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); |
109 | 0 |
|
110 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
111 | 0 | } |
112 | | |
113 | | TEST(TestXPathGenerator, TestEscapeNameWithNormalCharacters) |
114 | 0 | { |
115 | 0 | nsAutoString arg; |
116 | 0 | arg.AssignLiteral(u"testing"); |
117 | 0 |
|
118 | 0 | nsAutoString expectedResult; |
119 | 0 | expectedResult.AssignLiteral(u"testing"); |
120 | 0 |
|
121 | 0 | nsAutoString result; |
122 | 0 | XPathGenerator::EscapeName(arg, result); |
123 | 0 |
|
124 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
125 | 0 | } |
126 | | |
127 | | TEST(TestXPathGenerator, TestEscapeNameWithSpecialCharacters) |
128 | 0 | { |
129 | 0 | nsAutoString arg; |
130 | 0 | arg.AssignLiteral(u"^testing!"); |
131 | 0 |
|
132 | 0 | nsAutoString expectedResult; |
133 | 0 | expectedResult.AssignLiteral(u"*[local-name()=\'^testing!\']"); |
134 | 0 |
|
135 | 0 | nsAutoString result; |
136 | 0 | XPathGenerator::EscapeName(arg, result); |
137 | 0 | printf("Result: %s\nExpected: %s\n", NS_ConvertUTF16toUTF8(result).get(), NS_ConvertUTF16toUTF8(expectedResult).get()); |
138 | 0 |
|
139 | 0 | ASSERT_TRUE(expectedResult.Equals(result)); |
140 | 0 | } |