added message wait queue test
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 1 Dec 2014 16:04:22 +0000 (18:04 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 1 Dec 2014 16:04:22 +0000 (18:04 +0200)
tests/test-libnetxms/Makefile.am
tests/test-libnetxms/nxcp.cpp [new file with mode: 0644]
tests/test-libnetxms/test-libnetxms.cpp
tests/test-libnetxms/test-libnetxms.vcproj

index 711d531..e1958eb 100644 (file)
@@ -9,7 +9,7 @@
 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 bin_PROGRAMS = test-libnetxms
-test_libnetxms_SOURCES = test-libnetxms.cpp
+test_libnetxms_SOURCES = nxcp.cpp test-libnetxms.cpp
 test_libnetxms_CPPFLAGS = -I@top_srcdir@/include -I../include
 test_libnetxms_LDADD = @top_srcdir@/src/libnetxms/libnetxms.la
 
diff --git a/tests/test-libnetxms/nxcp.cpp b/tests/test-libnetxms/nxcp.cpp
new file mode 100644 (file)
index 0000000..7a0db2d
--- /dev/null
@@ -0,0 +1,38 @@
+#include <nms_common.h>
+#include <nms_util.h>
+#include <nxcpapi.h>
+#include <testtools.h>
+
+/**
+ * Poster thread
+ */
+static THREAD_RESULT THREAD_CALL PosterThread(void *arg)
+{
+   NXCPMessage *msg = new NXCPMessage();
+   msg->setCode(CMD_REQUEST_COMPLETED);
+   msg->setId(42);
+   ThreadSleepMs((UINT32)GetCurrentTimeMs() % 2000);
+   ((MsgWaitQueue *)arg)->put(msg);
+   return THREAD_OK;
+}
+
+/**
+ * Test message wait queue
+ */
+void TestMsgWaitQueue()
+{
+   StartTest(_T("Message wait queue"));
+
+   MsgWaitQueue *queue = new MsgWaitQueue;
+   ThreadCreate(PosterThread, 0, queue);
+   NXCPMessage *msg = queue->waitForMessage(CMD_REQUEST_COMPLETED, 42, 5000);
+   AssertNotNull(msg);
+   delete msg;
+
+   msg = queue->waitForMessage(CMD_REQUEST_COMPLETED, 42, 1000);
+   AssertNull(msg);
+
+   delete queue;
+
+   EndTest();
+}
index d9a648a..bb787c4 100644 (file)
@@ -2,6 +2,8 @@
 #include <nms_util.h>
 #include <testtools.h>
 
+void TestMsgWaitQueue();
+
 static char mbText[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
 static WCHAR wcText[] = L"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
 static char mbTextShort[] = "Lorem ipsum";
@@ -187,5 +189,6 @@ int main(int argc, char *argv[])
    TestStringConversion();
    TestStringMap();
    TestStringSet();
+   TestMsgWaitQueue();
    return 0;
 }
index b509482..50685a8 100644 (file)
                        />
                </Configuration>
                <Configuration
-                       Name="Release|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
+                       Name="Debug|x64"
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
                        ConfigurationType="1"
                        CharacterSet="1"
-                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
+                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
+                               Optimization="0"
                                AdditionalIncludeDirectories="..\include;..\..\include"
-                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
-                               RuntimeLibrary="2"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="true"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               LinkIncremental="1"
+                               LinkIncremental="2"
                                GenerateDebugInformation="true"
                                SubSystem="1"
-                               OptimizeReferences="2"
-                               EnableCOMDATFolding="2"
-                               TargetMachine="1"
+                               TargetMachine="17"
                        />
                        <Tool
                                Name="VCALinkTool"
                        />
                </Configuration>
                <Configuration
-                       Name="Debug|x64"
-                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
-                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
                        ConfigurationType="1"
                        CharacterSet="1"
+                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
-                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               Optimization="0"
                                AdditionalIncludeDirectories="..\include;..\..\include"
-                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
-                               MinimalRebuild="true"
-                               BasicRuntimeChecks="3"
-                               RuntimeLibrary="3"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+                               RuntimeLibrary="2"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="true"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               LinkIncremental="2"
+                               LinkIncremental="1"
                                GenerateDebugInformation="true"
                                SubSystem="1"
-                               TargetMachine="17"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
                        />
                        <Tool
                                Name="VCALinkTool"
                        Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
+                       <File
+                               RelativePath=".\nxcp.cpp"
+                               >
+                       </File>
                        <File
                                RelativePath=".\test-libnetxms.cpp"
                                >