diff options
author | Pavel Kramchaninov <PKramchaninov@luxoft.com> | 2014-10-07 12:36:02 +0300 |
---|---|---|
committer | Pavel Kramchaninov <PKramchaninov@luxoft.com> | 2014-10-07 12:36:50 +0300 |
commit | 3b621c81d9a3127a555d5d7cb30326f980873da1 (patch) | |
tree | 39f144d8fa1369c345f8f807d9276d51312bf356 | |
parent | 2f21b8dc957c142967bb09b96e2d55db28abab1e (diff) | |
download | smartdevicelink-3b621c81d9a3127a555d5d7cb30326f980873da1.tar.gz |
APPLINK-9509: Unit-Test refactoring
-rw-r--r-- | src/appMain/CMakeLists.txt | 29 | ||||
-rw-r--r-- | src/appMain/main_test.cc | 61 | ||||
-rw-r--r-- | src/components/media_manager/CMakeLists.txt | 21 | ||||
-rwxr-xr-x | src/components/media_manager/src/main.cc | 7 | ||||
-rw-r--r-- | src/components/media_manager/src/media_adapter_impl_test.cc (renamed from test/components/utils/src/data_time_tests.cc) | 7 | ||||
-rw-r--r-- | src/components/utils/CMakeLists.txt | 21 | ||||
-rw-r--r-- | src/components/utils/src/date_time_test.cc | 128 | ||||
-rw-r--r-- | src/components/utils/src/file_system_test.cc | 111 | ||||
-rwxr-xr-x | src/components/utils/src/main.cc | 7 | ||||
-rw-r--r-- | test/components/utils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/components/utils/include/utils/data_time_tests.h | 127 | ||||
-rw-r--r-- | test/components/utils/include/utils/file_system_tests.h | 115 | ||||
-rw-r--r-- | test/components/utils/src/file_system_tests.cc | 31 |
13 files changed, 391 insertions, 276 deletions
diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt index 05dfb8102..9261961e9 100644 --- a/src/appMain/CMakeLists.txt +++ b/src/appMain/CMakeLists.txt @@ -111,11 +111,13 @@ include_directories ( ../components/transport_manager/include ${SecurityManagerIncludeDir} ../components/config_profile/include + ../components/utils/ ../components/utils/include/ ../components/connection_handler/include/ ../components/hmi_message_handler/include ../components/request_watchdog/include ../components/smart_objects/include/ + ../components/media_manager/ ../components/media_manager/include/ ${CMAKE_SOURCE_DIR}/src/components/time_tester/include ${CMAKE_SOURCE_DIR}/src/components/policy/src/policy/include/ @@ -156,6 +158,33 @@ endif() add_executable(${PROJECT} ${SOURCES}) target_link_libraries(${PROJECT} ${LIBRARIES}) + +#======================= Unit-Test section ======================= +if(BUILD_TESTS) + include_directories ( + ../3rd_party-static/gmock-1.7.0/include + ../3rd_party-static/gmock-1.7.0/gtest/include) + + set(testSources + ./main_test.cc + ../components/utils/src/file_system_test.cc + ../components/utils/src/date_time_test.cc + ../components/media_manager/src/media_adapter_impl_test.cc) + + set(testLibraries + gmock + gtest + ConfigProfile + log4cxx -L${LOG4CXX_LIBS_DIRECTORY} + apr-1 -L${APR_LIBS_DIRECTORY} + aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY} + expat -L${EXPAT_LIBS_DIRECTORY}) + + add_executable(${PROJECT}_test ${testSources}) + target_link_libraries(${PROJECT}_test ${testLibraries}) +endif() +#================================================================= + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/audio.8bit.wav DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/appMain/main_test.cc b/src/appMain/main_test.cc new file mode 100644 index 000000000..26da24ce1 --- /dev/null +++ b/src/appMain/main_test.cc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdlib.h> +#include <stdio.h> + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "config_profile/profile.h" +#include "utils/logger.h" + +#ifdef __cplusplus +extern "C" void __gcov_flush(); +#endif + +int main(int argc, char **argv) { + ::testing::InitGoogleMock(&argc, argv); + + profile::Profile::instance()->config_file_name("smartDeviceLink.ini"); + INIT_LOGGER("log4cxx.properties"); + + int result = RUN_ALL_TESTS(); + +#if defined(__cplusplus) and defined(GCOV_ENABLED) + __gcov_flush(); +#endif + + sleep(2); + DEINIT_LOGGER(); + return result; +} diff --git a/src/components/media_manager/CMakeLists.txt b/src/components/media_manager/CMakeLists.txt index a01ab852b..532cb8cd4 100644 --- a/src/components/media_manager/CMakeLists.txt +++ b/src/components/media_manager/CMakeLists.txt @@ -46,6 +46,8 @@ set(LIBRARIES endif() include_directories ( + /home/vagrant/Work/GIT/applink/src/3rd_party-static/gmock-1.7.0/include + /home/vagrant/Work/GIT/applink/src/3rd_party-static/gmock-1.7.0/gtest/include ./include ./include/audio/ ./include/video/ @@ -75,3 +77,22 @@ set (SOURCES add_library("MediaManager" ${SOURCES} ${default_sources}) target_link_libraries("MediaManager" ${LIBRARIES}) + +#======================= Unit-Test section ======================= +if(BUILD_TESTS) + include_directories ( + ../../3rd_party-static/gmock-1.7.0/include + ../../3rd_party-static/gmock-1.7.0/gtest/include) + + set(testSources + ./src/main.cc + ./src/media_adapter_impl_test.cc) + + set(testLibraries + gmock + gtest) + + add_executable(media_manager_test ${testSources}) + target_link_libraries(media_manager_test ${testLibraries}) +endif() +#================================================================= diff --git a/src/components/media_manager/src/main.cc b/src/components/media_manager/src/main.cc new file mode 100755 index 000000000..59fa20e8b --- /dev/null +++ b/src/components/media_manager/src/main.cc @@ -0,0 +1,7 @@ +#include "gmock/gmock.h"
+
+int main(int argc, char** argv) {
+ testing::InitGoogleMock(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
diff --git a/test/components/utils/src/data_time_tests.cc b/src/components/media_manager/src/media_adapter_impl_test.cc index daa3e650b..f6a6ffa51 100644 --- a/test/components/utils/src/data_time_tests.cc +++ b/src/components/media_manager/src/media_adapter_impl_test.cc @@ -29,4 +29,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "utils/data_time_tests.h" + +#include "gmock/gmock.h" + +TEST(MediaAdapterImplTest, DummyTest) { + ASSERT_TRUE(true); +} diff --git a/src/components/utils/CMakeLists.txt b/src/components/utils/CMakeLists.txt index 5b446f00f..74b798692 100644 --- a/src/components/utils/CMakeLists.txt +++ b/src/components/utils/CMakeLists.txt @@ -52,3 +52,24 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_link_libraries("Utils" pthread ${RTLIB}) endif() + +#======================= Unit-Test section ======================= +if(BUILD_TESTS) + include_directories ( + ../../3rd_party-static/gmock-1.7.0/include + ../../3rd_party-static/gmock-1.7.0/gtest/include) + + set(testSources + ./src/main.cc + ./src/file_system_test.cc + ./src/date_time_test.cc) + + set(testLibraries + gmock + gtest + Utils) + + add_executable(utils_test ${testSources}) + target_link_libraries(utils_test ${testLibraries}) +endif() +#================================================================= diff --git a/src/components/utils/src/date_time_test.cc b/src/components/utils/src/date_time_test.cc new file mode 100644 index 000000000..749a634f6 --- /dev/null +++ b/src/components/utils/src/date_time_test.cc @@ -0,0 +1,128 @@ +/* +* Copyright (c) 2014, Ford Motor Company +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright notice, this +* list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the +* distribution. +* +* Neither the name of the Ford Motor Company nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <unistd.h> + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "utils/date_time.h" + +namespace test { +namespace components { +namespace utils { + +TEST(DateTimeTest, GetCurrentTime) { + const TimevalStruct time1 = date_time::DateTime::getCurrentTime(); + ASSERT_NE(0, time1.tv_sec); + ASSERT_GE(time1.tv_usec, 0); + + const TimevalStruct time2 = date_time::DateTime::getCurrentTime(); + ASSERT_NE(0, time2.tv_sec); + ASSERT_GE(time2.tv_usec, 0); + ASSERT_GE(time2.tv_sec, time1.tv_sec); +} + +TEST(DateTimeTest, GetmSecs) { + TimevalStruct time; + time.tv_sec = 1; + time.tv_usec = 2 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS; + + ASSERT_EQ(time.tv_sec * date_time::DateTime::MILLISECONDS_IN_SECOND + + time.tv_usec / date_time::DateTime::MICROSECONDS_IN_MILLISECONDS, + date_time::DateTime::getmSecs(time)); +} + +TEST(DateTimeTest, GetuSecs) { + TimevalStruct time; + time.tv_sec = 3; + time.tv_usec = 4; + + ASSERT_EQ(time.tv_sec * date_time::DateTime::MILLISECONDS_IN_SECOND * + date_time::DateTime::MICROSECONDS_IN_MILLISECONDS + time.tv_usec, + date_time::DateTime::getuSecs(time)); +} + +TEST(DateTimeTest, GetuSecsmSecs) { + TimevalStruct time; + time.tv_sec = 5; + time.tv_usec = 6; + + ASSERT_EQ( date_time::DateTime::getmSecs(time), + date_time::DateTime::getuSecs(time) / date_time::DateTime::MICROSECONDS_IN_MILLISECONDS); +} + +TEST(DateTimeTest, CalculateTimeSpan) { + const TimevalStruct time = date_time::DateTime::getCurrentTime(); + + const uint32_t sleep_time_mSec = 10; + usleep(sleep_time_mSec * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS); + + ASSERT_GE(date_time::DateTime::calculateTimeSpan(time), + sleep_time_mSec); +} + +TEST(DateTimeTest, CalculateTimeDiff) { + TimevalStruct time1; + time1.tv_sec = 1; + time1.tv_usec = 2 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS; + + TimevalStruct time2; + time2.tv_sec = 3; + time2.tv_usec = 4 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS; + + //time2 to time1 + TimevalStruct diff1; + diff1.tv_sec = time2.tv_sec - time1.tv_sec; + diff1.tv_usec = time2.tv_usec - time1.tv_usec; + + const int64_t mSecDiff = static_cast<int64_t>(diff1.tv_sec) * 1000 + + diff1.tv_usec / 1000; + + ASSERT_EQ(mSecDiff, + date_time::DateTime::calculateTimeDiff(time2, time1)); + + //time1 to time2 + TimevalStruct diff2; + diff2.tv_sec = time1.tv_sec - time2.tv_sec; + diff2.tv_usec = time1.tv_usec - time2.tv_usec; + + const int64_t mSecDiff2 = static_cast<int64_t>(diff2.tv_sec) * 1000 + + diff2.tv_usec / 1000; + + ASSERT_EQ(mSecDiff2, + date_time::DateTime::calculateTimeDiff(time1, time2)); +} + +} // namespace utils +} // namespace components +} // namespace test diff --git a/src/components/utils/src/file_system_test.cc b/src/components/utils/src/file_system_test.cc new file mode 100644 index 000000000..abf09735b --- /dev/null +++ b/src/components/utils/src/file_system_test.cc @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2014, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gmock/gmock.h" +#include "utils/file_system.h" + +namespace test { +namespace components { +namespace utils { + +TEST(FileSystemTest, CommonFileSystemTest) { + // Directory creation + ASSERT_FALSE(file_system::DirectoryExists("./Test directory")); + + file_system::CreateDirectory("./Test directory"); + + ASSERT_TRUE(file_system::DirectoryExists("./Test directory")); + + ASSERT_TRUE(file_system::IsDirectory("./Test directory")); + + // File creation + ASSERT_FALSE(file_system::FileExists("./Test directory/test file")); + + std::vector<unsigned char> data; + data.push_back('t'); + data.push_back('e'); + data.push_back('s'); + data.push_back('t'); + + ASSERT_TRUE(file_system::Write("./Test directory/test file", data)); + + ASSERT_TRUE(file_system::FileExists("./Test directory/test file")); + + ASSERT_FALSE(file_system::IsDirectory("./Test directory/test file")); + + // Read data from file + std::vector<unsigned char> result; + + ASSERT_TRUE(file_system::ReadBinaryFile("./Test directory/test file", + result)); + ASSERT_FALSE(result.empty()); + + // list files + ASSERT_TRUE(file_system::Write("./Test directory/test file 2", data)); + + std::vector<std::string> list; + list = file_system::ListFiles("./Test directory"); + + ASSERT_FALSE(list.empty()); + std::sort(list.begin(), list.end()); + ASSERT_EQ("test file", list[0]); + ASSERT_EQ("test file 2", list[1]); + + // Delete file + ASSERT_TRUE(file_system::FileExists("./Test directory/test file 2")); + ASSERT_TRUE(file_system::DeleteFile("./Test directory/test file 2")); + ASSERT_FALSE(file_system::FileExists("./Test directory/test file 2")); + + // Delete empty directory + file_system::CreateDirectory("./Test directory/Empty directory"); + + ASSERT_TRUE(file_system::DirectoryExists( + "./Test directory/Empty directory")); + ASSERT_TRUE(file_system::RemoveDirectory( + "./Test directory/Empty directory", false)); + ASSERT_FALSE(file_system::DirectoryExists( + "./Test directory/Empty directory")); + + ASSERT_FALSE(file_system::RemoveDirectory("./Test directory", false)); + ASSERT_TRUE(file_system::DirectoryExists("./Test directory")); + + // Delete directory recursively + file_system::CreateDirectory("./Test directory/Test directory 2"); + ASSERT_TRUE(file_system::Write( + "./Test directory/Test directory 2/test file 2", data)); + ASSERT_TRUE(file_system::RemoveDirectory("./Test directory", true)); + + ASSERT_FALSE(file_system::DirectoryExists("./Test directory")); +} +} // namespace utils +} // namespace components +} // namespace test diff --git a/src/components/utils/src/main.cc b/src/components/utils/src/main.cc new file mode 100755 index 000000000..59fa20e8b --- /dev/null +++ b/src/components/utils/src/main.cc @@ -0,0 +1,7 @@ +#include "gmock/gmock.h"
+
+int main(int argc, char** argv) {
+ testing::InitGoogleMock(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
diff --git a/test/components/utils/CMakeLists.txt b/test/components/utils/CMakeLists.txt index b7acf6d56..c1e95550d 100644 --- a/test/components/utils/CMakeLists.txt +++ b/test/components/utils/CMakeLists.txt @@ -14,8 +14,6 @@ set(LIBRARIES ) set(SOURCES - ./src/file_system_tests.cc - ./src/data_time_tests.cc ./src/prioritized_queue_tests.cc ) diff --git a/test/components/utils/include/utils/data_time_tests.h b/test/components/utils/include/utils/data_time_tests.h deleted file mode 100644 index abb760f4f..000000000 --- a/test/components/utils/include/utils/data_time_tests.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -* Copyright (c) 2014, Ford Motor Company -* All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* Redistributions of source code must retain the above copyright notice, this -* list of conditions and the following disclaimer. -* -* Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following -* disclaimer in the documentation and/or other materials provided with the -* distribution. -* -* Neither the name of the Ford Motor Company nor the names of its contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ -#ifndef DATA_TIME_TESTS_H -#define DATA_TIME_TESTS_H - -#include <unistd.h> - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "utils/date_time.h" - -namespace test { -namespace components { -namespace utils { - TEST(DateTimeTest, GetCurrentTime) { - const TimevalStruct time1 = date_time::DateTime::getCurrentTime(); - ASSERT_NE(0, time1.tv_sec); - ASSERT_GE(time1.tv_usec, 0); - - const TimevalStruct time2 = date_time::DateTime::getCurrentTime(); - ASSERT_NE(0, time2.tv_sec); - ASSERT_GE(time2.tv_usec, 0); - ASSERT_GE(time2.tv_sec, time1.tv_sec); - } - - TEST(DateTimeTest, GetmSecs) { - TimevalStruct time; - time.tv_sec = 1; - time.tv_usec = 2 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS; - - ASSERT_EQ(time.tv_sec * date_time::DateTime::MILLISECONDS_IN_SECOND + - time.tv_usec / date_time::DateTime::MICROSECONDS_IN_MILLISECONDS, - date_time::DateTime::getmSecs(time)); - } - TEST(DateTimeTest, GetuSecs) { - TimevalStruct time; - time.tv_sec = 3; - time.tv_usec = 4; - - ASSERT_EQ(time.tv_sec * date_time::DateTime::MILLISECONDS_IN_SECOND * - date_time::DateTime::MICROSECONDS_IN_MILLISECONDS + time.tv_usec, - date_time::DateTime::getuSecs(time)); - } - TEST(DateTimeTest, GetuSecsmSecs) { - TimevalStruct time; - time.tv_sec = 5; - time.tv_usec = 6; - - ASSERT_EQ( date_time::DateTime::getmSecs(time), - date_time::DateTime::getuSecs(time) / date_time::DateTime::MICROSECONDS_IN_MILLISECONDS); - } - - TEST(DateTimeTest, CalculateTimeSpan) { - const TimevalStruct time = date_time::DateTime::getCurrentTime(); - - const uint32_t sleep_time_mSec = 10; - usleep(sleep_time_mSec * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS); - - ASSERT_GE(date_time::DateTime::calculateTimeSpan(time), - sleep_time_mSec); - } - - TEST(DateTimeTest, CalculateTimeDiff) { - TimevalStruct time1; - time1.tv_sec = 1; - time1.tv_usec = 2 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS; - - TimevalStruct time2; - time2.tv_sec = 3; - time2.tv_usec = 4 * date_time::DateTime::MICROSECONDS_IN_MILLISECONDS; - - //time2 to time1 - TimevalStruct diff1; - diff1.tv_sec = time2.tv_sec - time1.tv_sec; - diff1.tv_usec = time2.tv_usec - time1.tv_usec; - - const int64_t mSecDiff = static_cast<int64_t>(diff1.tv_sec) * 1000 - + diff1.tv_usec / 1000; - - ASSERT_EQ(mSecDiff, - date_time::DateTime::calculateTimeDiff(time2, time1)); - - //time1 to time2 - TimevalStruct diff2; - diff2.tv_sec = time1.tv_sec - time2.tv_sec; - diff2.tv_usec = time1.tv_usec - time2.tv_usec; - - const int64_t mSecDiff2 = static_cast<int64_t>(diff2.tv_sec) * 1000 - + diff2.tv_usec / 1000; - - ASSERT_EQ(mSecDiff2, - date_time::DateTime::calculateTimeDiff(time1, time2)); - } -} // namespace utils -} // namespace components -} // namespace test -#endif // DATA_TIME_TESTS_H diff --git a/test/components/utils/include/utils/file_system_tests.h b/test/components/utils/include/utils/file_system_tests.h deleted file mode 100644 index aefca92f3..000000000 --- a/test/components/utils/include/utils/file_system_tests.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2013, Ford Motor Company -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following -// disclaimer in the documentation and/or other materials provided with the -// distribution. -// -// Neither the name of the Ford Motor Company nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 'A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -#ifndef TEST_COMPONENTS_UTILS_INCLUDE_REQUEST_UTILS_FILE_SYSTEM_TESTS_H_ -#define TEST_COMPONENTS_UTILS_INCLUDE_REQUEST_UTILS_FILE_SYSTEM_TESTS_H_ - -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "utils/file_system.h" - -namespace test { -namespace components { -namespace utils { - TEST(FileSystemTest, CommonFileSystemTest) { - // Directory creation - ASSERT_FALSE(file_system::DirectoryExists("./Test directory")); - - file_system::CreateDirectory("./Test directory"); - - ASSERT_TRUE(file_system::DirectoryExists("./Test directory")); - - ASSERT_TRUE(file_system::IsDirectory("./Test directory")); - - // File creation - ASSERT_FALSE(file_system::FileExists("./Test directory/test file")); - - std::vector<unsigned char> data; - data.push_back('t'); - data.push_back('e'); - data.push_back('s'); - data.push_back('t'); - - ASSERT_TRUE(file_system::Write("./Test directory/test file", data)); - - ASSERT_TRUE(file_system::FileExists("./Test directory/test file")); - - ASSERT_FALSE(file_system::IsDirectory("./Test directory/test file")); - - // Read data from file - std::vector<unsigned char> result; - - ASSERT_TRUE(file_system::ReadBinaryFile("./Test directory/test file", - result)); - ASSERT_FALSE(result.empty()); - - // list files - ASSERT_TRUE(file_system::Write("./Test directory/test file 2", data)); - - std::vector<std::string> list; - list = file_system::ListFiles("./Test directory"); - - ASSERT_FALSE(list.empty()); - std::sort(list.begin(), list.end()); - ASSERT_EQ("test file", list[0]); - ASSERT_EQ("test file 2", list[1]); - - // Delete file - ASSERT_TRUE(file_system::FileExists("./Test directory/test file 2")); - ASSERT_TRUE(file_system::DeleteFile("./Test directory/test file 2")); - ASSERT_FALSE(file_system::FileExists("./Test directory/test file 2")); - - // Delete empty directory - file_system::CreateDirectory("./Test directory/Empty directory"); - - ASSERT_TRUE(file_system::DirectoryExists( - "./Test directory/Empty directory")); - ASSERT_TRUE(file_system::RemoveDirectory( - "./Test directory/Empty directory", false)); - ASSERT_FALSE(file_system::DirectoryExists( - "./Test directory/Empty directory")); - - ASSERT_FALSE(file_system::RemoveDirectory("./Test directory", false)); - ASSERT_TRUE(file_system::DirectoryExists("./Test directory")); - - // Delete directory recursively - file_system::CreateDirectory("./Test directory/Test directory 2"); - ASSERT_TRUE(file_system::Write( - "./Test directory/Test directory 2/test file 2", data)); - ASSERT_TRUE(file_system::RemoveDirectory("./Test directory", true)); - - ASSERT_FALSE(file_system::DirectoryExists("./Test directory")); - } -} // namespace utils -} // namespace components -} // namespace test - -#endif //TEST_COMPONENTS_UTILS_INCLUDE_REQUEST_UTILS_FILE_SYSTEM_TESTS_H_ diff --git a/test/components/utils/src/file_system_tests.cc b/test/components/utils/src/file_system_tests.cc deleted file mode 100644 index 107b7092b..000000000 --- a/test/components/utils/src/file_system_tests.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2013, Ford Motor Company -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following -// disclaimer in the documentation and/or other materials provided with the -// distribution. -// -// Neither the name of the Ford Motor Company nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 'A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -#include "utils/file_system_tests.h" |