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

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

commit 18d3171174d582cce5d5302012d54797f097177b
Author: Robert Middleton <[email protected]>
AuthorDate: Sun Jan 2 13:35:46 2022 -0500

    Added tests for location info
---
 src/main/cpp/locationinfo.cpp                      |  2 +-
 .../include/log4cxx/spi/location/locationinfo.h    |  4 +-
 src/test/cpp/CMakeLists.txt                        |  4 ++
 src/test/cpp/locationdisabledtest.cpp              | 75 ++++++++++++++++++++++
 src/test/cpp/locationtest.cpp                      | 75 ++++++++++++++++++++++
 src/test/resources/input/location1.properties      | 21 ++++++
 .../resources/input/locationdisabled.properties    | 21 ++++++
 src/test/resources/witness/location1-disabled      |  1 +
 src/test/resources/witness/location1-good          |  1 +
 9 files changed, 201 insertions(+), 3 deletions(-)

diff --git a/src/main/cpp/locationinfo.cpp b/src/main/cpp/locationinfo.cpp
index 707a4e4..cc6775d 100644
--- a/src/main/cpp/locationinfo.cpp
+++ b/src/main/cpp/locationinfo.cpp
@@ -51,7 +51,7 @@ LocationInfo::LocationInfo( const char* const fileName1,
 }
 
 LocationInfo::LocationInfo( const char* const fileName1,
-                                                       int shortFilenameOffset,
+                                                       size_t 
shortFilenameOffset,
        const char* const methodName1,
        int lineNumber1 )
        :  lineNumber( lineNumber1 ),
diff --git a/src/main/include/log4cxx/spi/location/locationinfo.h 
b/src/main/include/log4cxx/spi/location/locationinfo.h
index 9346476..6587305 100644
--- a/src/main/include/log4cxx/spi/location/locationinfo.h
+++ b/src/main/include/log4cxx/spi/location/locationinfo.h
@@ -57,7 +57,7 @@ class LOG4CXX_EXPORT LocationInfo
                        int lineNumber);
 
                LocationInfo( const char* const fileName,
-                                         int shortFileNameOffset,
+                                         size_t shortFileNameOffset,
                        const char* const functionName,
                        int lineNumber);
 
@@ -156,7 +156,7 @@ class LOG4CXX_EXPORT LocationInfo
 #endif
 
 #define LOG4CXX_LOCATION_CREATE ::std::string_view file_name{__FILE__};\
-       const int short_filename_offset = 
file_name.find_last_of(LOG4CXX_SHORT_FILENAME_SPLIT_CHAR) + 1;\
+       const size_t short_filename_offset = 
file_name.find_last_of(LOG4CXX_SHORT_FILENAME_SPLIT_CHAR) + 1;\
        ::log4cxx::spi::LocationInfo location(__FILE__,         \
        short_filename_offset, \
        __LOG4CXX_FUNC__, \
diff --git a/src/test/cpp/CMakeLists.txt b/src/test/cpp/CMakeLists.txt
index 11701da..bd985f9 100644
--- a/src/test/cpp/CMakeLists.txt
+++ b/src/test/cpp/CMakeLists.txt
@@ -38,6 +38,8 @@ set(ALL_LOG4CXX_TESTS
     rollingfileappendertestcase
     streamtestcase
     multithreadtest
+    locationtest
+    locationdisabledtest
 )
 foreach(fileName IN LISTS ALL_LOG4CXX_TESTS)
     add_executable(${fileName} "${fileName}.cpp")
@@ -129,3 +131,5 @@ foreach(testName IN LISTS ALL_LOG4CXX_TESTS)
         endif()
     endif()
 endforeach()
+
+target_compile_definitions(locationdisabledtest PRIVATE 
LOG4CXX_DISABLE_LOCATION_INFO)
diff --git a/src/test/cpp/locationdisabledtest.cpp 
b/src/test/cpp/locationdisabledtest.cpp
new file mode 100644
index 0000000..fa682f6
--- /dev/null
+++ b/src/test/cpp/locationdisabledtest.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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 <log4cxx/logger.h>
+#include <log4cxx/propertyconfigurator.h>
+
+#include "testchar.h"
+#include "logunit.h"
+#include "util/compare.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+LOGUNIT_CLASS(LocationDisabledTest)
+{
+       LOGUNIT_TEST_SUITE(LocationDisabledTest);
+       LOGUNIT_TEST(test1);
+       LOGUNIT_TEST_SUITE_END();
+
+       LoggerPtr root;
+       LoggerPtr logger;
+
+public:
+       void setUp()
+       {
+               root = Logger::getRootLogger();
+       }
+
+       void tearDown()
+       {
+               if (auto rep = root->getLoggerRepository())
+                       rep->resetConfiguration();
+       }
+
+       void test1()
+       {
+               
PropertyConfigurator::configure(LOG4CXX_FILE("input/locationdisabled.properties"));
+               common();
+               
LOGUNIT_ASSERT(Compare::compare(LOG4CXX_STR("output/location-disabled-test"), 
LOG4CXX_FILE("witness/location1-disabled")));
+       }
+
+       std::string createMessage(Pool & pool, int i)
+       {
+               std::string msg("Message ");
+               msg.append(pool.itoa(i));
+               return msg;
+       }
+
+       void common()
+       {
+               int i = -1;
+
+               Pool pool;
+
+               LOG4CXX_DEBUG(root, createMessage(pool, i));
+       }
+
+};
+
+
+LOGUNIT_TEST_SUITE_REGISTRATION(LocationDisabledTest);
diff --git a/src/test/cpp/locationtest.cpp b/src/test/cpp/locationtest.cpp
new file mode 100644
index 0000000..aa98a63
--- /dev/null
+++ b/src/test/cpp/locationtest.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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 <log4cxx/logger.h>
+#include <log4cxx/propertyconfigurator.h>
+
+#include "testchar.h"
+#include "logunit.h"
+#include "util/compare.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+LOGUNIT_CLASS(LocationTest)
+{
+       LOGUNIT_TEST_SUITE(LocationTest);
+       LOGUNIT_TEST(test1);
+       LOGUNIT_TEST_SUITE_END();
+
+       LoggerPtr root;
+       LoggerPtr logger;
+
+public:
+       void setUp()
+       {
+               root = Logger::getRootLogger();
+       }
+
+       void tearDown()
+       {
+               if (auto rep = root->getLoggerRepository())
+                       rep->resetConfiguration();
+       }
+
+       void test1()
+       {
+               
PropertyConfigurator::configure(LOG4CXX_FILE("input/location1.properties"));
+               common();
+               
LOGUNIT_ASSERT(Compare::compare(LOG4CXX_STR("output/location-good-test"), 
LOG4CXX_FILE("witness/location1-good")));
+       }
+
+       std::string createMessage(Pool & pool, int i)
+       {
+               std::string msg("Message ");
+               msg.append(pool.itoa(i));
+               return msg;
+       }
+
+       void common()
+       {
+               int i = -1;
+
+               Pool pool;
+
+               LOG4CXX_DEBUG(root, createMessage(pool, i));
+       }
+
+};
+
+
+LOGUNIT_TEST_SUITE_REGISTRATION(LocationTest);
diff --git a/src/test/resources/input/location1.properties 
b/src/test/resources/input/location1.properties
new file mode 100644
index 0000000..f220ebd
--- /dev/null
+++ b/src/test/resources/input/location1.properties
@@ -0,0 +1,21 @@
+# 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.
+#
+log4j.rootCategory=DEBUG, testAppender
+log4j.appender.testAppender=org.apache.log4j.FileAppender
+log4j.appender.testAppender.file=output/location-good-test
+log4j.appender.testAppender.Append=false
+log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.testAppender.layout.ConversionPattern=%-5p(%f) - %m%n
diff --git a/src/test/resources/input/locationdisabled.properties 
b/src/test/resources/input/locationdisabled.properties
new file mode 100644
index 0000000..191b3b4
--- /dev/null
+++ b/src/test/resources/input/locationdisabled.properties
@@ -0,0 +1,21 @@
+# 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.
+#
+log4j.rootCategory=DEBUG, testAppender
+log4j.appender.testAppender=org.apache.log4j.FileAppender
+log4j.appender.testAppender.file=output/location-disabled-test
+log4j.appender.testAppender.Append=false
+log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.testAppender.layout.ConversionPattern=%-5p[%F](%f)%L|%M| - %m%n
diff --git a/src/test/resources/witness/location1-disabled 
b/src/test/resources/witness/location1-disabled
new file mode 100644
index 0000000..f63de46
--- /dev/null
+++ b/src/test/resources/witness/location1-disabled
@@ -0,0 +1 @@
+DEBUG[?](?)-1|?| - Message -1
diff --git a/src/test/resources/witness/location1-good 
b/src/test/resources/witness/location1-good
new file mode 100644
index 0000000..6ee4319
--- /dev/null
+++ b/src/test/resources/witness/location1-good
@@ -0,0 +1 @@
+DEBUG(locationtest.cpp) - Message -1

Reply via email to