cunit: add network stream unit tests.
authorVic Lee <llyzs@163.com>
Sat, 2 Jul 2011 15:39:35 +0000 (23:39 +0800)
committerVic Lee <llyzs@163.com>
Sat, 2 Jul 2011 15:39:35 +0000 (23:39 +0800)
cunit/CMakeLists.txt
cunit/test_freerdp.c
cunit/test_network.c [new file with mode: 0644]
cunit/test_network.h [new file with mode: 0644]

index 58c9326..d765d14 100644 (file)
@@ -9,6 +9,8 @@ add_executable(test_freerdp
        test_color.h
        test_libgdi.c
        test_libgdi.h
+       test_network.c
+       test_network.h
        test_freerdp.c
        test_freerdp.h)
 
index 22d5487..1826211 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "test_color.h"
 #include "test_libgdi.h"
+#include "test_network.h"
 #include "test_freerdp.h"
 
 void dump_data(unsigned char * p, int len, int width, char* name)
@@ -61,6 +62,7 @@ int main(int argc, char* argv[])
        {
                add_color_suite();
                add_libgdi_suite();
+               add_network_suite();
        }
        else
        {
@@ -74,6 +76,10 @@ int main(int argc, char* argv[])
                        {
                                add_libgdi_suite();
                        }
+                       else if (strcmp("network", argv[*pindex]) == 0)
+                       {
+                               add_network_suite();
+                       }
 
                        *pindex = *pindex + 1;
                }
diff --git a/cunit/test_network.c b/cunit/test_network.c
new file mode 100644 (file)
index 0000000..b5a2d4c
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Client
+ * Network Tests
+ *
+ * Copyright 2011 Vic Lee
+ *
+ * Licensed 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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <freerdp/freerdp.h>
+#include <freerdp/utils/hexdump.h>
+#include <freerdp/utils/stream.h>
+
+#include "test_network.h"
+
+int init_network_suite(void)
+{
+       return 0;
+}
+
+int clean_network_suite(void)
+{
+       return 0;
+}
+
+int add_network_suite(void)
+{
+       add_test_suite(network);
+
+       add_test_function(network_stream);
+}
+
+void test_network_stream(void)
+{
+       STREAM * stream;
+       int pos;
+       uint32 n;
+       uint64 n64;
+
+       stream = stream_new(1);
+       pos = stream_get_pos(stream);
+
+       stream_write_uint8(stream, 0xFE);
+
+       stream_check_capacity(stream, 14);
+       stream_write_uint16(stream, 0x0102);
+       stream_write_uint32(stream, 0x03040506);
+       stream_write_uint64(stream, 0x0708091011121314LL);
+
+       /*freerdp_hexdump(stream->buffer, 15);*/
+
+       stream_set_pos(stream, pos);
+       stream_seek(stream, 3);
+       stream_read_uint32(stream, n);
+       stream_read_uint64(stream, n64);
+
+       CU_ASSERT(n == 0x03040506);
+       CU_ASSERT(n64 == 0x0708091011121314LL);
+
+       stream_free(stream);
+}
diff --git a/cunit/test_network.h b/cunit/test_network.h
new file mode 100644 (file)
index 0000000..b1916d1
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Client
+ * Network Tests
+ *
+ * Copyright 2011 Vic Lee
+ *
+ * Licensed 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 "test_freerdp.h"
+
+int init_network_suite(void);
+int clean_network_suite(void);
+int add_network_suite(void);
+
+void test_network_stream(void);
+