You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/03/01 18:42:10 UTC
svn commit: r1295697 - in /incubator/etch/trunk/binding-cpp/runtime:
include/util/EtchURL.h src/main/CMakeLists.txt src/main/util/EtchURL.cpp
src/test/CMakeLists.txt src/test/util/EtchURLTest.cpp
Author: veithm
Date: Thu Mar 1 17:42:10 2012
New Revision: 1295697
URL: http://svn.apache.org/viewvc?rev=1295697&view=rev
Log:
ETCH-174 EtchURL Implementation & Tests
Change-Id: I99aa2c97110f3ed743b07daba7b1dd30d34a10d8
Added:
incubator/etch/trunk/binding-cpp/runtime/include/util/EtchURL.h
incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchURL.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchURLTest.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
Added: incubator/etch/trunk/binding-cpp/runtime/include/util/EtchURL.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/util/EtchURL.h?rev=1295697&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/util/EtchURL.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/util/EtchURL.h Thu Mar 1 17:42:10 2012
@@ -0,0 +1,300 @@
+/* $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.
+ */
+
+#ifndef __ETCHURL_H__
+#define __ETCHURL_H__
+#include "common/EtchError.h"
+#include "common/EtchString.h"
+#include "common/EtchHashTable.h"
+#include "common/EtchList.h"
+#include "util/EtchUtil.h"
+#include "common/EtchConfig.h"
+#include "capu/os/StringUtils.h"
+
+class EtchURL {
+public:
+
+ /**
+ * Constructs an empty url.
+ */
+ EtchURL();
+
+ /**
+ * Constructs a url from a string
+ * @param urlStr
+ */
+ EtchURL(const char * urlStr);
+
+ /**
+ * Constructs a url from a string.
+ * @param urlStr
+ */
+ EtchURL(EtchString& urlStr);
+
+ /**
+ * Deconstructor
+ */
+ virtual ~EtchURL();
+
+ /**
+ * @return the scheme.
+ */
+ EtchString& getScheme();
+
+ /**
+ * Sets the scheme.
+ *
+ * @param scheme the scheme to set which may be null but not blank.
+ */
+ void setScheme(EtchString& scheme);
+
+ /**
+ * Sets the scheme.
+ *
+ * @param scheme the scheme to set which may be null but not blank.
+ */
+ status_t setScheme(EtchString* scheme);
+
+ /**
+ * Tests the scheme for a match. The schemes are case-insensitive.
+ *
+ * @param testScheme a scheme to test against.
+ *
+ * @return true if the schemes match, false otherwise.
+ */
+ capu::bool_t isScheme(EtchString& testScheme);
+
+ //////////
+ // USER //
+ //////////
+
+ /**
+ * @return the user.
+ */
+ EtchString& getUser();
+
+ /**
+ * Sets the user.
+ *
+ * @param user the user to set which may be null but not blank.
+ */
+ void setUser(EtchString& user);
+
+ //////////////
+ // PASSWORD //
+ //////////////
+
+ /**
+ * @return the password.
+ */
+ EtchString& getPassword();
+
+ /**
+ * Sets the password.
+ *
+ * @param password the password to set which may be null but not blank.
+ */
+ void setPassword(EtchString& password);
+
+ //////////
+ // HOST //
+ //////////
+
+ /**
+ * @return the host.
+ */
+ EtchString& getHost();
+
+ /**
+ * Sets the host.
+ *
+ * @param host the host to set which may be null but not blank.
+ */
+ void setHost(EtchString& host);
+
+ //////////
+ // PORT //
+ //////////
+
+ /**
+ * @return true if a port has been specified, false otherwise.
+ */
+ capu::bool_t hasPort();
+
+ /**
+ * @return the port. Null if no port has been specified.
+ */
+ capu::uint16_t getPort();
+
+ /**
+ * Sets the port.
+ *
+ * @param port the port to set which may be between 0 and 65535.
+ */
+ void setPort(capu::uint16_t port);
+
+ /////////
+ // URI //
+ /////////
+
+ /**
+ * @return the uri.
+ */
+ EtchString& getUri();
+
+ /**
+ * Sets the uri.
+ *
+ * @param uri the uri to set which may be null or blank.
+ */
+ void setUri(EtchString& uri);
+
+ ////////////
+ // PARAMS //
+ ////////////
+
+ /**
+ * @return true if there is at least one param.
+ */
+ capu::bool_t hasParams();
+
+ /**
+ * Adds a param to the list of params for this url. Only the unique
+ * params are maintained. Duplicate param values are suppressed.
+ *
+ * @param param a param (e.g., "transport=tcp" or "01831864574898475").
+ */
+ void addParam(EtchString& param);
+
+ /**
+ * Removes all the params.
+ */
+ void clearParams();
+
+ /////////////////
+ // QUERY TERMS //
+ /////////////////
+
+ /**
+ * Adds the specified query term to the list of query terms. Duplicate
+ * name/value pairs are suppressed.
+ * @param name
+ * @param value
+ * @return ETCH_EINVAL if the parameters are NULL
+ * ETCH_OK if term is successfully added
+ * ETCH_ENO_MEMORY if allocation of term is failed
+ */
+ status_t addTerm(EtchString& name, EtchString& value);
+
+ /**
+ * Adds the specified query term to the list of query terms. Duplicate
+ * name/value pairs are suppressed.
+ * @param name
+ * @param value
+ * @return ETCH_EINVAL if the parameters are NULL
+ * ETCH_OK if term is successfully added
+ * ETCH_ENO_MEMORY if allocation of term is failed
+ */
+ status_t addTerm(EtchString& name, capu::int32_t value);
+
+ /**
+ * Adds the specified query term to the list of query terms. Duplicate
+ * name/value pairs are suppressed.
+ * @param name
+ * @param value
+ * @return ETCH_EINVAL if the parameters are NULL
+ * ETCH_OK if term is successfully added
+ * ETCH_ENO_MEMORY if allocation of term is failed
+ */
+ status_t addTerm(EtchString& name, capu::double_t value);
+
+ /**
+ * Adds the specified query term to the list of query terms. Duplicate
+ * name/value pairs are suppressed.
+ * @param name
+ * @param value
+ * @return ETCH_EINVAL if the parameters are NULL
+ * ETCH_OK if term is successfully added
+ * ETCH_ENO_MEMORY if allocation of term is failed
+ */
+ status_t addTerm(EtchString& name, capu::bool_t value);
+
+ /**
+ * Removes all the query terms.
+ */
+ void clearTerms();
+
+
+ //////////////
+ // FRAGMENT //
+ //////////////
+
+ /**
+ * @return the fragment.
+ */
+ EtchString& getFragment();
+
+ /**
+ * Sets the fragment.
+ *
+ * @param fragment the fragment to set which may be null but not blank.
+ */
+ void setFragment(EtchString& fragment);
+
+ /**
+ *
+ * @return list of parameters
+ */
+ EtchList<EtchString>& getParams();
+
+ /**
+ *
+ * @return hash table which composed of terms
+ */
+ EtchHashTable<EtchString, EtchString>& getTerms();
+
+private:
+
+ EtchString scheme;
+ EtchString user;
+ EtchString password;
+ EtchString host;
+ capu::uint16_t port;
+ EtchString uri;
+ EtchString fragment;
+ EtchList<EtchString> params;
+ EtchHashTable<EtchString, EtchString> terms;
+
+ status_t parse(EtchString* s);
+
+ status_t parseHost(EtchString* s);
+
+ status_t parseUserPassword(EtchString* s);
+
+ status_t parseHostPort(EtchString* s);
+
+ status_t parseParams(EtchString* s);
+
+ status_t parseTerms(EtchString* s);
+
+ status_t parseTerm(EtchString *s);
+
+};
+
+#endif
+
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1295697&r1=1295696&r2=1295697&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Thu Mar 1 17:42:10 2012
@@ -37,11 +37,12 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/common/EtchHash.h
${PROJECT_SOURCE_DIR}/include/common/EtchHashNative.h
${PROJECT_SOURCE_DIR}/include/common/EtchHashTable.h
- ${PROJECT_SOURCE_DIR}/include/common/EtchList.h
+ ${PROJECT_SOURCE_DIR}/include/common/EtchList.h
${PROJECT_SOURCE_DIR}/include/common/EtchNative.h
${PROJECT_SOURCE_DIR}/include/common/EtchNativeArray.h
${PROJECT_SOURCE_DIR}/include/common/EtchSocket.h
${PROJECT_SOURCE_DIR}/include/common/EtchServerSocket.h
+ ${PROJECT_SOURCE_DIR}/include/util/EtchURL.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
)
@@ -58,6 +59,7 @@ SET(MAIN_SOURCES
common/EtchDouble.cpp
common/EtchSocket.cpp
common/EtchServerSocket.cpp
+ util/EtchURL.cpp
util/EtchUtil.cpp
)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchURL.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchURL.cpp?rev=1295697&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchURL.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchURL.cpp Thu Mar 1 17:42:10 2012
@@ -0,0 +1,421 @@
+/* $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 "util/EtchURL.h"
+#include "capu/os/StringUtils.h"
+
+EtchURL::EtchURL() {
+
+}
+
+EtchURL::EtchURL(const char* urlStr) {
+ if (urlStr == NULL) {
+ //already initialized
+ } else if (strlen(urlStr) > 0) {
+ EtchString str(urlStr);
+ if (parse(&str) != ETCH_OK) {
+ fragment.set("");
+ host.set("");
+ password.set("");
+ port = 0;
+ scheme.set("");
+ uri.set("");
+ user.set("");
+ }
+ }
+}
+
+EtchURL::EtchURL(EtchString& urlStr) {
+ if (urlStr.c_str() == NULL) {
+ //already initialized
+ } else if (urlStr.length() > 0) {
+ if (parse(&urlStr) != ETCH_OK) {
+ fragment.set("");
+ host.set("");
+ password.set("");
+ port = 0;
+ scheme.set("");
+ uri.set("");
+ user.set("");
+ }
+ }
+}
+
+EtchURL::~EtchURL() {
+ params.clear();
+ terms.clear();
+}
+
+status_t EtchURL::parse(EtchString* s) {
+ if (s == NULL)
+ return ETCH_EINVAL;
+ // s is scheme:[//[user[:password]@]host[:port]/]uri[;params][?terms][#fragment]
+ capu::int32_t result = s->leftFind(':');
+ status_t error_result;
+ if (result == -1)
+ return ETCH_ERROR;
+ //parsing of scheme
+ EtchString x[2];
+ //x[0] contains scheme
+ error_result = s->substring(0, result, &x[0]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //x[1] will contain rest of url [//[user[:password]@]host[:port]/]uri[;params][?terms][#fragment]
+ error_result = s->substring(result + 1, s->length()-(result + 1), &x[1]);
+ if (error_result != ETCH_OK)
+ return error_result;
+
+ setScheme(x[0]);
+ EtchString _s(x[1]);
+
+ // _s is [//[user[:password]@]host[:port]/]uri[;params][?terms][#fragment]
+ result = _s.leftFind('#');
+
+ if (result != -1) {
+ //parse the fragments
+ //x[0] will contain the rest of url [//[user[:password]@]host[:port]/]uri[;params][?terms]
+ error_result = _s.substring(0, result, &x[0]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //x[1] will contain the fragments
+ error_result = _s.substring(result + 1, _s.length()-(result + 1), &x[1]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //set the fragments
+ setFragment(x[1]);
+ _s = x[0];
+ }
+
+ // s is [//[user[:password]@]host[:port]/]uri[;params][?terms]
+ result = _s.leftFind('?');
+
+ if (result != -1) {
+ //parse terms
+ //x[0] will contain rest of url [//[user[:password]@]host[:port]/]uri[;params]
+ error_result = _s.substring(0, result, &x[0]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //x[1] will contain the terms
+ error_result = _s.substring(result + 1, _s.length()-(result + 1), &x[1]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //parse and sets the terms
+ error_result = parseTerms(&x[1]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ _s = x[0];
+ }
+
+ // s is [//[user[:password]@]host[:port]/]uri[;params]
+ result = _s.leftFind(';');
+ if (result != -1) {
+ //parse terms
+ //x[0] will contain rest of url [//[user[:password]@]host[:port]/]uri
+ error_result = _s.substring(0, result, &x[0]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ error_result = _s.substring(result + 1, _s.length()-(result + 1), &x[1]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //x[1] will contain the params
+ error_result = parseParams(&x[1]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ _s = x[0];
+ }
+
+ // s is [//[user[:password]@]host[:port]/]uri
+ char *str = new char [_s.length() + 1];
+ etch_strcpy_s(str, _s.length() + 1, _s.c_str());
+
+ if ((str[0] == '/') && (str[1] == '/')) {
+ //eleminate "//"
+ _s.set(&str[2]);
+ // s is [user[:password]@]host[:port]/uri
+ //parse uri
+ result = _s.leftFind('/');
+ if (result != -1) {
+ //x[0] contains rest of uri [user[:password]@]host[:port]
+ error_result = _s.substring(0, result, &x[0]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //x[1] will contain the uri
+ error_result = _s.substring(result + 1, _s.length()-(result + 1), &x[1]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ // parse [user[:password]@]host[:port]
+ error_result = parseHost(&x[0]);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //now s contains the uri
+ _s = x[1];
+ } else {
+ // s is [user[:password]@]host[:port]
+ error_result = parseHost(&_s);
+ if (error_result != ETCH_OK)
+ return error_result;
+ //uri is not given
+ _s.set("");
+ }
+ }
+ setUri(_s);
+ delete [] str;
+ return ETCH_OK;
+}
+
+status_t EtchURL::parseHost(EtchString* s) {
+ if (s == NULL) {
+ return ETCH_EINVAL;
+ }
+ // s is [user[:password]@]host[:port]
+ capu::int32_t result = s->leftFind('@');
+ EtchString x[2];
+ if (result != -1) {
+ if (s->substring(0, result, &x[0]) != ETCH_OK)
+ return ETCH_ERROR;
+ if (s->substring(result + 1, s->length()-(result + 1), &x[1]) != ETCH_OK)
+ return ETCH_ERROR;
+ parseUserPassword(&x[0]);
+ parseHostPort(&x[1]);
+ } else {
+ parseHostPort(s);
+ }
+ return ETCH_OK;
+}
+
+status_t EtchURL::parseUserPassword(EtchString* s) {
+ if (s == NULL) {
+ return ETCH_EINVAL;
+ }
+ // s is user[:password]
+ capu::int32_t result = s->leftFind(':');
+
+ EtchString x[2];
+
+ if (result != -1) {
+ if (s->substring(0, result, &x[0]) != ETCH_OK)
+ return ETCH_ERROR;
+ if (s->substring(result + 1, s->length()-(result + 1), &x[1]) != ETCH_OK)
+ return ETCH_ERROR;
+ setUser(x[0]);
+ setPassword(x[1]);
+ } else {
+ setUser(*s);
+ }
+ return ETCH_OK;
+}
+
+status_t EtchURL::parseHostPort(EtchString* s) {
+ if (s == NULL) {
+ return ETCH_EINVAL;
+ }
+ capu::int32_t result = s->leftFind(':');
+
+ EtchString x[2];
+
+ if (x != NULL) {
+ if (s->substring(0, result, &x[0]) != ETCH_OK)
+ return ETCH_ERROR;
+ if (s->substring(result + 1, s->length()-(result + 1), &x[1]) != ETCH_OK)
+ return ETCH_ERROR;
+ setHost(x[0]);
+ EtchString *p = &x[1];
+ capu::int32_t _port = atoi(p->c_str());
+ setPort(_port);
+ } else {
+ setHost(*s);
+ }
+ return ETCH_OK;
+}
+
+status_t EtchURL::parseParams(EtchString* s) {
+ // s is param[;param]*
+ if (s == NULL) {
+ return ETCH_EINVAL;
+ }
+ if (s->length() == 0)
+ return ETCH_OK; //THERE IS NOTHING TO PARSE
+ EtchString _s = *s;
+ EtchString x[2];
+ capu::int32_t result = _s.leftFind(';');
+ while (result != -1) {
+ if (_s.substring(0, result, &x[0]) != ETCH_OK)
+ return ETCH_ERROR;
+ if (_s.substring(result + 1, _s.length()-(result + 1), &x[1]) != ETCH_OK)
+ return ETCH_ERROR;
+ addParam(x[0]);
+ _s.set(x[1].c_str());
+ result = _s.leftFind(';');
+ }
+ addParam(_s);
+ return ETCH_OK;
+}
+
+status_t EtchURL::parseTerms(EtchString* s) {
+ if (s == NULL) {
+ return ETCH_EINVAL;
+ }
+ if (s->length() == 0)
+ return ETCH_OK; //THERE IS NOTHING TO PARSE
+ EtchString _s = *s;
+ EtchString x[2];
+ capu::int32_t result = _s.leftFind('&');
+ while (result != -1) {
+ if (_s.substring(0, result, &x[0]) != ETCH_OK)
+ return ETCH_ERROR;
+ if (_s.substring(result + 1, _s.length()-(result + 1), &x[1]) != ETCH_OK)
+ return ETCH_ERROR;
+ parseTerm(&x[0]);
+ _s.set(x[1].c_str());
+ result = _s.leftFind('&');
+ }
+ return parseTerm(&_s);
+}
+
+status_t EtchURL::parseTerm(EtchString * s) {
+ if (s == NULL) {
+ return ETCH_EINVAL;
+ }
+ // s is name[=value]
+ if (s->length() == 0)
+ return ETCH_OK; //THERE IS NOTHING TO PARSE
+ capu::int32_t result = s->leftFind('=');
+ EtchString x[2];
+ if (s->substring(0, result, &x[0]) != ETCH_OK)
+ return ETCH_ERROR;
+ if (s->substring(result + 1, s->length()-(result + 1), &x[1]) != ETCH_OK)
+ return ETCH_ERROR;
+ if (result != -1)
+ addTerm(x[0], x[1]);
+ return ETCH_OK;
+}
+
+EtchString& EtchURL::getScheme() {
+ return scheme;
+}
+
+void EtchURL::setScheme(EtchString& scheme) {
+ this->scheme.set(scheme.c_str());
+}
+
+status_t EtchURL::setScheme(EtchString* scheme) {
+ if (scheme != NULL) {
+ this->scheme.set(scheme->c_str());
+ } else {
+ return ETCH_EINVAL;
+ }
+}
+
+EtchString& EtchURL::getUser() {
+ return user;
+}
+
+void EtchURL::setUser(EtchString& user) {
+ this->user.set(user.c_str());
+}
+
+EtchString& EtchURL::getPassword() {
+ return password;
+}
+
+void EtchURL::setPassword(EtchString& password) {
+ this->password.set(password.c_str());
+}
+
+EtchString& EtchURL::getHost() {
+ return host;
+}
+
+void EtchURL::setHost(EtchString& host) {
+ this->host.set(host.c_str());
+}
+
+capu::uint16_t EtchURL::getPort() {
+ return port;
+}
+
+void EtchURL::setPort(capu::uint16_t port) {
+ this->port = port;
+}
+
+EtchString& EtchURL::getUri() {
+ return uri;
+}
+
+void EtchURL::setUri(EtchString& uri) {
+ this->uri.set(uri.c_str());
+}
+
+capu::bool_t EtchURL::hasParams() {
+ return !(params.isEmpty());
+}
+
+void EtchURL::addParam(EtchString& param) {
+ this->params.add(param);
+}
+
+void EtchURL::clearParams() {
+ params.clear();
+}
+
+status_t EtchURL::addTerm(EtchString& name, EtchString& value) {
+ return terms.put(name, value);
+}
+
+status_t EtchURL::addTerm(EtchString& name, capu::int32_t value) {
+ char result [10];
+ EtchString str;
+ capu::StringUtils::Sprintf(result, 10, "%d", value);
+ str.set(result);
+ return addTerm(name, str);
+}
+
+status_t EtchURL::addTerm(EtchString& name, capu::bool_t value) {
+ char result [2];
+ EtchString str;
+ capu::StringUtils::Sprintf(result, 2, "%d", value);
+ str.set(result);
+ return addTerm(name, str);
+}
+
+status_t EtchURL::addTerm(EtchString& name, capu::double_t value) {
+ char result [10];
+ EtchString str;
+ capu::StringUtils::Sprintf(result, 10, "%f", value);
+ str.set(result);
+ return addTerm(name, str);
+}
+
+void EtchURL::clearTerms() {
+ terms.clear();
+}
+
+EtchString& EtchURL::getFragment() {
+ return fragment;
+}
+
+void EtchURL::setFragment(EtchString& fragment) {
+ this->fragment.set(fragment.c_str());
+}
+
+EtchList<EtchString>& EtchURL::getParams() {
+ return params;
+}
+
+EtchHashTable<EtchString, EtchString>& EtchURL::getTerms() {
+ return terms;
+}
\ No newline at end of file
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt?rev=1295697&r1=1295696&r2=1295697&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Thu Mar 1 17:42:10 2012
@@ -41,6 +41,7 @@ add_executable (etch-cpp-test
common/EtchNativeArrayTest.cpp
common/EtchHashTableTest.cpp
common/EtchHashSetTest.cpp
+ util/EtchURLTest.cpp
util/EtchUtilTest.cpp
${GTEST}/src/gtest-all.cc
main.cpp
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchURLTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchURLTest.cpp?rev=1295697&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchURLTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchURLTest.cpp Thu Mar 1 17:42:10 2012
@@ -0,0 +1,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);
+}
\ No newline at end of file