-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEtchURLTest.cpp
More file actions
137 lines (113 loc) · 4 KB
/
EtchURLTest.cpp
File metadata and controls
137 lines (113 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* $Id$
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version
* 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "util/EtchURL.h"
#include "common/EtchString.h"
TEST(EtchURLTest, constructorTest) {
EtchURL * url = new EtchURL("tcp://admin:metreos@localhost:10000/uri;param2;param1?term1=value1&term2=value2#frag");
EXPECT_TRUE(url != NULL);
delete url;
}
TEST(EtchURLTest, getTests) {
EtchURL url("tcp://admin:metreos@localhost:10000/uri;param2;param1?term1=value1&term2=value2#frag");
EXPECT_TRUE(strcmp(url.getScheme().c_str(), "tcp") == 0);
EXPECT_TRUE(strcmp(url.getFragment().c_str(), "frag") == 0);
EXPECT_TRUE(strcmp(url.getUser().c_str(), "admin") == 0);
EXPECT_TRUE(strcmp(url.getPassword().c_str(), "metreos") == 0);
EXPECT_TRUE(strcmp(url.getHost().c_str(), "localhost") == 0);
EXPECT_TRUE(strcmp(url.getUri().c_str(), "uri") == 0);
EXPECT_TRUE(url.getPort() == 10000);
}
TEST(EtchURLTest, setAndGetTests) {
EtchString defScheme("tcp");
EtchString defUser("admin");
EtchString defPassword("metreos");
EtchString defHost("localhost");
EtchString defFragment("frag");
capu::int32_t defPort = 10000;
EtchString defUri("uri");
EtchURL url;
url.setFragment(defFragment);
url.setHost(defHost);
url.setPassword(defPassword);
url.setPort(defPort);
url.setUri(defUri);
url.setScheme(defScheme);
url.setUser(defUser);
EXPECT_TRUE(strcmp(defFragment.c_str(), url.getFragment().c_str()) == 0);
EXPECT_TRUE(strcmp(defScheme.c_str(), url.getScheme().c_str()) == 0);
EXPECT_TRUE(strcmp(defUser.c_str(), url.getUser().c_str()) == 0);
EXPECT_TRUE(strcmp(defPassword.c_str(), url.getPassword().c_str()) == 0);
EXPECT_TRUE(strcmp(defHost.c_str(), url.getHost().c_str()) == 0);
EXPECT_TRUE(strcmp(defUri.c_str(), url.getUri().c_str()) == 0);
EXPECT_TRUE(defPort == url.getPort());
}
TEST(EtchURLTest, AddParamTest) {
EtchString tmp("");
EtchString defUri("uri");
EtchURL url;
//url.addParam(NULL);
//should not add invalid parameters
EXPECT_TRUE(url.getParams().size() == 0);
url.addParam(defUri);
EXPECT_TRUE(url.getParams().size() == 1);
url.getParams().get(0, &tmp);
EXPECT_TRUE(tmp.equals(&defUri));
}
TEST(EtchURLTest, AddTermTest) {
EtchString tmp("");
EtchString defKey("key");
EtchString defUri("uri");
EtchURL url;
EXPECT_TRUE(url.getTerms().count() == 0);
url.addTerm(defKey, defUri);
EXPECT_TRUE(url.getTerms().count() == 1);
url.getTerms().get(defKey, &tmp);
EXPECT_TRUE(tmp.equals(&defUri));
}
TEST(EtchURLTest, HasParamTest) {
EtchString tmp("");
EtchString defUri("uri");
EtchURL url;
EXPECT_FALSE(url.hasParams());
url.addParam(defUri);
EXPECT_TRUE(url.getParams().size() == 1);
EXPECT_TRUE(url.hasParams());
url.getParams().get(0, &tmp);
EXPECT_TRUE(tmp.equals(&defUri));
}
TEST(EtchURLTest, clearParamTest) {
EtchString tmp("");
EtchString defUri("uri");
EtchURL url;
url.addParam(defUri);
EXPECT_TRUE(url.getParams().size() == 1);
//clear the params
url.clearParams();
EXPECT_TRUE(url.getParams().size() == 0);
}
TEST(EtchURLTest, clearTermTest) {
EtchString tmp("");
EtchString defUri("uri");
EtchString defKey("key");
EtchURL url;
url.addTerm(defKey, defUri);
EXPECT_TRUE(url.getTerms().count() == 1);
//clear the terms
url.clearTerms();
EXPECT_TRUE(url.getTerms().count() == 0);
}