diff options
author | Laurent Goujon <laurent@dremio.com> | 2016-08-22 14:54:19 -0700 |
---|---|---|
committer | Parth Chandra <parthc@apache.org> | 2016-11-01 11:29:58 -0700 |
commit | 3a35a4200e748ed557c55d6d13ac995cce28ab09 (patch) | |
tree | ab99ff78cae79e703be0b686663fb1a4331766c4 /contrib/native/client/src | |
parent | 2558803ecdfc961bb630e9e2372255c44f986d06 (diff) |
DRILL-1268: Add unit test to C++ native client
Add CppUnit unit test to the C++ native client
Diffstat (limited to 'contrib/native/client/src')
-rw-r--r-- | contrib/native/client/src/clientlib/utils.hpp | 2 | ||||
-rw-r--r-- | contrib/native/client/src/test/CMakeLists.txt | 40 | ||||
-rw-r--r-- | contrib/native/client/src/test/UtilsTest.cpp | 51 | ||||
-rw-r--r-- | contrib/native/client/src/test/main.cpp | 39 |
4 files changed, 131 insertions, 1 deletions
diff --git a/contrib/native/client/src/clientlib/utils.hpp b/contrib/native/client/src/clientlib/utils.hpp index 36fb91f81..3237aa333 100644 --- a/contrib/native/client/src/clientlib/utils.hpp +++ b/contrib/native/client/src/clientlib/utils.hpp @@ -62,7 +62,7 @@ class AllocatedBuffer{ }; -class Utils{ +class DECLSPEC_DRILL_CLIENT Utils{ public: static boost::random::random_device s_RNG; //Truly random (expensive and device dependent) static boost::random::mt19937 s_URNG; //Pseudo random with a period of ( 2^19937 - 1 ) diff --git a/contrib/native/client/src/test/CMakeLists.txt b/contrib/native/client/src/test/CMakeLists.txt new file mode 100644 index 000000000..892b58c46 --- /dev/null +++ b/contrib/native/client/src/test/CMakeLists.txt @@ -0,0 +1,40 @@ +# +# 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. +# + +# Drill Client unit tests +set (TESTS_SRC_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/UtilsTest.cpp + ) + +find_package(CppUnit REQUIRED) +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include ) +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../clientlib ) +include_directories(${CPPUNIT_INCLUDE_DIR}) +include_directories(${Boost_INCLUDE_DIRS}) +include_directories(${PROTOBUF_INCLUDE_DIR}) +include_directories(${Zookeeper_INCLUDE_DIRS}) + +link_directories(/usr/local/lib) +add_executable(unit-tests ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ${TESTS_SRC_FILES} ) +target_link_libraries(unit-tests drillClient protomsgs y2038 ${CPPUNIT_LIBRARY} ${Boost_LIBRARIES} ${PROTOBUF_LIBRARY} ${Zookeeper_LIBRARIES}) + +foreach(testfile ${TESTS_SRC_FILES}) +get_filename_component(testname ${testfile} NAME_WE) +add_test(NAME ${testname} + COMMAND unit-tests ${testname}) +endforeach(testfile) diff --git a/contrib/native/client/src/test/UtilsTest.cpp b/contrib/native/client/src/test/UtilsTest.cpp new file mode 100644 index 000000000..0fba45e20 --- /dev/null +++ b/contrib/native/client/src/test/UtilsTest.cpp @@ -0,0 +1,51 @@ +/* + * 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 <string> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include "utils.hpp" + +class UtilsTest: public CppUnit::TestFixture { +public: + UtilsTest() {} + + CPPUNIT_TEST_SUITE( UtilsTest ); + CPPUNIT_TEST(testParseConnectStr); + CPPUNIT_TEST_SUITE_END(); + + + void testParseConnectStr() { + std::string protocol; + std::string hostAndPort; + std::string path; + + Drill::Utils::parseConnectStr("local=localhost:12345/path/to/drill", + path, + protocol, + hostAndPort); + + CPPUNIT_ASSERT(protocol == "local"); + CPPUNIT_ASSERT(hostAndPort == "localhost:12345"); + CPPUNIT_ASSERT(path == "/path/to/drill"); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); diff --git a/contrib/native/client/src/test/main.cpp b/contrib/native/client/src/test/main.cpp new file mode 100644 index 000000000..e5e17101d --- /dev/null +++ b/contrib/native/client/src/test/main.cpp @@ -0,0 +1,39 @@ +/* + * 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 <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/ui/text/TestRunner.h> + +int main( int argc, char **argv) +{ + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry(); + + CppUnit::Test* testSuite = registry.makeTest(); + CppUnit::Test* test; + if (argc > 1) { + test = testSuite->findTest(argv[1]); + } + else { + test = testSuite; + } + + runner.addTest( testSuite ); + bool wasSuccessful = runner.run("", false ); + return !wasSuccessful; +} |