Browse Source

replaced main.c by unit tests skeletons

Leon Urbas 11 years ago
parent
commit
ca8df49837
4 changed files with 45 additions and 84 deletions
  1. 37 38
      tests/check_stack.c
  2. 6 4
      tool/Makefile.am
  3. 0 40
      tool/main.c
  4. 2 2
      tool/opcua_basictypes.h

+ 37 - 38
tests/check_stack.c

@@ -26,8 +26,8 @@ START_TEST(test_getPacketType_validParameter)
 	char buf[] = {'C','L','O'};
 	Int32 pos = 0;
 	UA_ByteString msg;
-	msg.Data = buf;
-	msg.Length = 3;
+	msg.data = buf;
+	msg.length = 3;
 
 	ck_assert_int_eq(TL_getPacketType(&msg, &pos),packetType_CLO);
 }
@@ -439,8 +439,8 @@ START_TEST(encodeUAString_test)
 	Int32 l = 11;
 	char mem[11] = "ACPLT OPCUA";
 	char *dstBuf = (char*) malloc(sizeof(Int32)+l);
-	string.Data =  mem;
-	string.Length = 11;
+	string.data =  mem;
+	string.length = 11;
 
 	encodeUAString(&string, &pos, dstBuf);
 
@@ -459,13 +459,13 @@ START_TEST(decodeUAString_test)
 	char binString[15] = {11,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A'};
 
 	char *dstBuf = (char*) malloc(l-sizeof(Int32));
-	string.Data = dstBuf;
-	string.Length = 0;
+	string.data = dstBuf;
+	string.length = 0;
 	decodeUAString(binString, &pos, &string);
 
 
-	ck_assert_int_eq(string.Length,11);
-	ck_assert_int_eq(string.Data[3],'L');
+	ck_assert_int_eq(string.length,11);
+	ck_assert_int_eq(string.data[3],'L');
 
 
 }
@@ -477,12 +477,12 @@ START_TEST(diagnosticInfo_calcSize_test)
 	Int32 valreal = 0;
 	Int32 valcalc = 0;
 	UA_DiagnosticInfo diagnosticInfo;
-	diagnosticInfo.EncodingMask = 0x01 | 0x02 | 0x04 | 0x08 | 0x10;
-	diagnosticInfo.SymbolicId = 30;
-	diagnosticInfo.NamespaceUri = 25;
-	diagnosticInfo.LocalizedText = 22;
-	diagnosticInfo.AdditionalInfo.Data = "OPCUA";
-	diagnosticInfo.AdditionalInfo.Length = 5;
+	diagnosticInfo.encodingMask = 0x01 | 0x02 | 0x04 | 0x08 | 0x10;
+	diagnosticInfo.symbolicId = 30;
+	diagnosticInfo.namespaceUri = 25;
+	diagnosticInfo.localizedText = 22;
+	diagnosticInfo.additionalInfo.data = "OPCUA";
+	diagnosticInfo.additionalInfo.length = 5;
 
 	valcalc = diagnosticInfo_calcSize(&diagnosticInfo);
 	valreal = 26;
@@ -503,15 +503,15 @@ START_TEST(extensionObject_calcSize_test)
 	ck_assert_int_eq(extensionObject_calcSize(&the_empty_UA_ExtensionObject), 1 + 1 + 1);
 
 	// empty ExtensionObject, handcoded
-	extensionObject.TypeId.EncodingByte = NIEVT_TWO_BYTE;
-	extensionObject.TypeId.Identifier.Numeric = 0;
-	extensionObject.Encoding = NO_BODY_IS_ENCODED;
+	extensionObject.typeId.encodingByte = NIEVT_TWO_BYTE;
+	extensionObject.typeId.identifier.numeric = 0;
+	extensionObject.encoding = NO_BODY_IS_ENCODED;
 	ck_assert_int_eq(extensionObject_calcSize(&extensionObject), 1 + 1 + 1);
 
 	// ExtensionObject with ByteString-Body
-	extensionObject.Encoding = BODY_IS_BYTE_STRING;
-	extensionObject.Body.Data = data;
-	extensionObject.Body.Length = 3;
+	extensionObject.encoding = BODY_IS_BYTE_STRING;
+	extensionObject.body.data = data;
+	extensionObject.body.length = 3;
 	ck_assert_int_eq(extensionObject_calcSize(&extensionObject), 3 + 4 + 3);
 
 }
@@ -524,15 +524,15 @@ START_TEST(responseHeader_calcSize_test)
 	UA_ExtensionObject extensionObject;
 
 	//Should have the size of 26 Bytes
-	diagnosticInfo.EncodingMask = DIEMT_SYMBOLIC_ID | DIEMT_NAMESPACE | DIEMT_LOCALIZED_TEXT | DIEMT_LOCALE | DIEMT_ADDITIONAL_INFO;		// Byte:   1
+	diagnosticInfo.encodingMask = DIEMT_SYMBOLIC_ID | DIEMT_NAMESPACE | DIEMT_LOCALIZED_TEXT | DIEMT_LOCALE | DIEMT_ADDITIONAL_INFO;		// Byte:   1
 	// Indices into to Stringtable of the responseHeader (62541-6 §5.5.12 )
-	diagnosticInfo.SymbolicId = -1;										// Int32:  4
-	diagnosticInfo.NamespaceUri = -1;									// Int32:  4
-	diagnosticInfo.LocalizedText = -1;									// Int32:  4
-	diagnosticInfo.Locale = -1;											// Int32:  4
+	diagnosticInfo.symbolicId = -1;										// Int32:  4
+	diagnosticInfo.namespaceUri = -1;									// Int32:  4
+	diagnosticInfo.localizedText = -1;									// Int32:  4
+	diagnosticInfo.locale = -1;											// Int32:  4
 	// Additional Info
-	diagnosticInfo.AdditionalInfo.Length = 5;							// Int32:  4
-	diagnosticInfo.AdditionalInfo.Data = "OPCUA";						// Byte[]: 5
+	diagnosticInfo.additionalInfo.length = 5;							// Int32:  4
+	diagnosticInfo.additionalInfo.data = "OPCUA";						// Byte[]: 5
 	responseHeader.serviceDiagnostics = &diagnosticInfo;
 	ck_assert_int_eq(diagnosticInfo_calcSize(&diagnosticInfo),1+(4+4+4+4)+(4+5));
 
@@ -563,10 +563,10 @@ START_TEST(encodeDataValue_test)
 	char *buf = (char*)opcua_malloc(15);
 	UA_DateTime dateTime;
 	dateTime = 80;
-	dataValue.ServerTimestamp = dateTime;
+	dataValue.serverTimestamp = dateTime;
 
 	//--without Variant
-	dataValue.EncodingMask = 0x08; //Only the SourvePicoseconds
+	dataValue.encodingMask = 0x08; //Only the SourvePicoseconds
 	encodeDataValue(&dataValue, &pos, buf);
 
 	ck_assert_int_eq(pos, 9);// represents the length
@@ -583,15 +583,14 @@ START_TEST(encodeDataValue_test)
 	//TestCase for a DataValue with a Variant!
 	//ToDo: Need to be checked after the function for encoding variants has been implemented
 	pos = 0;
-	dataValue.EncodingMask = 0x01 || 0x08; //Variant & SourvePicoseconds
+	dataValue.encodingMask = 0x01 || 0x08; //Variant & SourvePicoseconds
 	UA_Variant variant;
-	variant.ArrayLength = 0;
-	variant.EncodingMask = VTEMT_INT32;
+	dataValue.value.arrayLength = 0;
+	dataValue.value.encodingMask = VTEMT_INT32;
 	UA_VariantUnion variantUnion;
 	//ToDo: needs to be adjusted: variantUnion.Int32 = 45;
 	fail(); ////ToDo: needs to be adjusted: Just to see that see that this needs to be adjusted
-	variant.Value = &variantUnion;
-	dataValue.Value = variant;
+	dataValue.value.data = &variantUnion;
 	encodeDataValue(&dataValue, &pos, buf);
 
 	ck_assert_int_eq(pos, 14);// represents the length
@@ -610,14 +609,14 @@ END_TEST
 START_TEST(DataValue_calcSize_test)
 {
 	UA_DataValue dataValue;
-	dataValue.EncodingMask = 0x02 + 0x04 + 0x10;
-	dataValue.Status = 12;
+	dataValue.encodingMask = 0x02 + 0x04 + 0x10;
+	dataValue.status = 12;
 	UA_DateTime dateTime;
 	dateTime = 80;
-	dataValue.SourceTimestamp = dateTime;
+	dataValue.sourceTimestamp = dateTime;
 	UA_DateTime sourceTime;
 	dateTime = 214;
-	dataValue.SourcePicoseconds = sourceTime;
+	dataValue.sourcePicoseconds = sourceTime;
 
 	int size = 0;
 	size = DataValue_calcSize(&dataValue);

+ 6 - 4
tool/Makefile.am

@@ -1,8 +1,7 @@
-bin_PROGRAMS = test_tool
-test_tool_SOURCES = main.c opcua_basictypes.c opcua.c opcua_namespace_0.c opcua.h opcua_namespace_0.h
-#test_tool_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/include
+bin_PROGRAMS = check
+check_SOURCES = check_stack.c opcua_basictypes.c opcua.c opcua_namespace_0.c opcua.h opcua_namespace_0.h
 
-main.c: opcua.h opcua_namespace_0.h
+check_stack.c: opcua.h opcua_namespace_0.h
 
 opcua.c opcua.h: Opc.Ua.Types.bsd generate_builtin.py
 	python generate_builtin.py Opc.Ua.Types.bsd opcua
@@ -17,4 +16,7 @@ clean-autogenerated:
 
 clean-local: clean-autogenerated
 
+INCLUDE = @CHECK_CFLAGS@ -I$(top_builddir)/src -I$(top_builddir)/include
+LDADD = $(top_builddir)/lib/libopen62541.a @CHECK_LIBS@
+
 AM_CFLAGS = $(GLOBAL_AM_CFLAGS)

+ 0 - 40
tool/main.c

@@ -1,40 +0,0 @@
-/*
- * main.c
- *
- *  Created on: 07.03.2014
- *      Author: mrt
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
-
-#include "opcua.h"
-
-int main() {
-	char* buf;
-	int pos = 0, retval, size;
-
-	// the value to encode
-	UA_Int32 i = -42, j;
-
-	// get buffer for encoding
-	size = UA_Int32_calcSize(UA_NULL);
-	buf = (char *) malloc(size);
-	printf("buf=%p, size=%d\n", buf, size);
-	if (buf == UA_NULL) return -1;
-
-	// encode
-	pos = 0;
-	retval = UA_Int32_encode(&i, &pos, buf);
-	printf("retval=%d, src=%d, pos=%d, buf={%d,%d,%d,%d}\n", retval, i, pos, buf[0], buf[1], buf[2], buf[3]);
-
-	// decode
-	pos = 0;
-	retval = UA_Int32_decode(buf, &pos, &j);
-	printf("retval=%d, dst=%d, pos=%d, {%d,%d,%d,%d}\n", retval, j, pos, buf[0], buf[1], buf[2], buf[3]);
-
-	// return memory
-	free(buf);
-	return 0;
-}
-

+ 2 - 2
tool/opcua_basictypes.h

@@ -25,8 +25,8 @@ typedef double Double;
 
 /* Basic types */
 typedef _Bool UA_Boolean;
-typedef int8_t UA_Byte;
-typedef uint8_t UA_SByte;
+typedef uint8_t UA_Byte;
+typedef int8_t UA_SByte;
 typedef int16_t UA_Int16;
 typedef uint16_t UA_UInt16;
 typedef int32_t UA_Int32;