]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4519: file_api: add unit-tests to cover new FileInfo methods
authorOleg Torubara -X (otorubar - SOFTSERVE INC at Cisco) <otorubar@cisco.com>
Wed, 20 Nov 2024 19:35:29 +0000 (19:35 +0000)
committerSteve Chew (stechew) <stechew@cisco.com>
Wed, 20 Nov 2024 19:35:29 +0000 (19:35 +0000)
Merge in SNORT/snort3 from ~OTORUBAR/snort3:suppress_unused_functions_errors to master

Squashed commit of the following:

commit 2ae7fbbf689f31d1e374d70da5779b7627e295e7
Author: otorubar <otorubar@cisco.com>
Date:   Fri Nov 15 07:59:17 2024 -0800

    file_api: add unit tests for fileinfo methods

src/file_api/file_lib.cc

index 71287405fc529801b7d57ff7765976aa1ece7314..b2e9d42c75c199a7d169682b4f1c5d883cb4529b 100644 (file)
 #include "pub_sub/intrinsic_event_ids.h"
 #include "utils/util.h"
 
+#ifdef UNIT_TEST
+#include "catch/snort_catch.h"
+#endif
+
 #include "file_api.h"
 #include "file_cache.h"
 #include "file_capture.h"
@@ -182,15 +186,16 @@ void FileInfo::unset_file_name()
     file_name_set = false;
 }
 
- void FileInfo::reset_sha()
- {
+// cppcheck-suppress unusedFunction
+void FileInfo::reset_sha()
+{
     if (sha256)
     {
         delete [] sha256;
         sha256 = nullptr;
         file_state.sig_state = FILE_SIG_PROCESSING;
     }
- }
+}
 
 void FileInfo::set_url(const char* url_name, uint32_t url_size)
 {
@@ -990,3 +995,33 @@ void FileContext::print(std::ostream& log)
     log << "File size: " << file_size << std::endl;
     log << "Processed size: " << processed_bytes << std::endl;
 }
+
+//--------------------------------------------------------------------------
+// unit tests
+//--------------------------------------------------------------------------
+
+#ifdef UNIT_TEST
+
+class FI_TEST : public FileInfo
+{ };
+
+TEST_CASE ("unset_file_name", "[file_info]")
+{
+    FI_TEST info;
+    info.set_file_name("test", 4);
+
+    CHECK ( true == info.is_file_name_set());
+
+    info.unset_file_name();
+    CHECK (false == info.is_file_name_set());
+}
+
+TEST_CASE ("get_url", "[file_info]")
+{
+    FI_TEST info;
+    info.set_url("/var/tmp/test.pdf", 17);
+    CHECK (info.get_url() == std::string("/var/tmp/test.pdf"));
+}
+
+#endif
+