This is an automated email from the ASF dual-hosted git repository.

rmiddleton pushed a commit to branch LOGCXX-431
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/LOGCXX-431 by this push:
     new 187c181  Added unit test for the thread utility
187c181 is described below

commit 187c1812479266aadc7a010a572eccc7cdf523e9
Author: Robert Middleton <[email protected]>
AuthorDate: Sat Aug 21 11:25:32 2021 -0400

    Added unit test for the thread utility
---
 src/test/cpp/helpers/CMakeLists.txt            |  1 +
 src/test/cpp/helpers/threadutilitytestcase.cpp | 74 ++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/src/test/cpp/helpers/CMakeLists.txt 
b/src/test/cpp/helpers/CMakeLists.txt
index c40681c..fda8194 100644
--- a/src/test/cpp/helpers/CMakeLists.txt
+++ b/src/test/cpp/helpers/CMakeLists.txt
@@ -18,6 +18,7 @@ set(HELPER_TESTS
     syslogwritertest
     timezonetestcase
     transcodertestcase
+    threadutilitytestcase
 )
 foreach(fileName IN LISTS HELPER_TESTS)
     add_executable(${fileName} "${fileName}.cpp")
diff --git a/src/test/cpp/helpers/threadutilitytestcase.cpp 
b/src/test/cpp/helpers/threadutilitytestcase.cpp
new file mode 100644
index 0000000..1aacb62
--- /dev/null
+++ b/src/test/cpp/helpers/threadutilitytestcase.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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 "../logunit.h"
+#include <log4cxx/helpers/threadutility.h>
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+
+LOGUNIT_CLASS(ThreadUtilityTest)
+{
+       LOGUNIT_TEST_SUITE(ThreadUtilityTest);
+       LOGUNIT_TEST(testNullFunctions);
+       LOGUNIT_TEST(testCustomFunctions);
+       LOGUNIT_TEST_SUITE_END();
+
+public:
+       void testNullFunctions(){
+               ThreadUtilityPtr thrUtil = ThreadUtility::instance();
+
+               thrUtil->configureThreadFunctions( nullptr, nullptr, nullptr );
+
+               std::thread t = thrUtil->createThread( "FooName", [](){} );
+
+               t.join();
+       }
+
+       void testCustomFunctions(){
+               ThreadUtilityPtr thrUtil = ThreadUtility::instance();
+               int num_pre = 0;
+               int num_started = 0;
+               int num_post = 0;
+
+               thrUtil->configureThreadFunctions( [&num_pre](){
+                       num_pre++;
+               },
+               [&num_started]( LogString,
+               std::thread::id,
+               std::thread::native_handle_type ){
+                       num_started++;
+               },
+               [&num_post](){
+                       num_post++;
+               });
+
+               std::thread t = thrUtil->createThread( "FooName", [](){} );
+
+               t.join();
+
+               LOGUNIT_ASSERT_EQUAL( num_pre, 1 );
+               LOGUNIT_ASSERT_EQUAL( num_started, 1 );
+               LOGUNIT_ASSERT_EQUAL( num_post, 1 );
+       }
+
+};
+
+
+LOGUNIT_TEST_SUITE_REGISTRATION(ThreadUtilityTest);
+

Reply via email to