Browse Source

stack now both single and multi-threaded

Leon Urbas 11 years ago
parent
commit
a440b2033e
7 changed files with 219 additions and 1165 deletions
  1. 6 2
      examples/src/Makefile.am
  2. 16 6
      examples/src/opcuaServer.c
  3. 24 0
      examples/src/opcuaServerMT.c
  4. 12 1
      include/ua_stack.h
  5. 161 40
      src/ua_stack.c
  6. 0 212
      tests/check_calcSize.c
  7. 0 904
      tests/check_generated.c

+ 6 - 2
examples/src/Makefile.am

@@ -1,9 +1,13 @@
 
-bin_PROGRAMS= $(top_builddir)/bin/exampleServer $(top_builddir)/bin/simpleTest
+bin_PROGRAMS= $(top_builddir)/bin/exampleServer $(top_builddir)/bin/exampleServerMT $(top_builddir)/bin/simpleTest
 #__top_builddir__bin_exampleServer_LDFLAGS = -all-static
 __top_builddir__bin_exampleServer_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/include
 __top_builddir__bin_exampleServer_SOURCES = opcuaServer.c
-__top_builddir__bin_exampleServer_LDADD= $(top_builddir)/lib/libopen62541.a -lpthread
+__top_builddir__bin_exampleServer_LDADD= $(top_builddir)/lib/libopen62541.a
+
+__top_builddir__bin_exampleServerMT_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/include
+__top_builddir__bin_exampleServerMT_SOURCES = opcuaServerMT.c
+__top_builddir__bin_exampleServerMT_LDADD= $(top_builddir)/lib/libopen62541.a -lpthread
 
 __top_builddir__bin_simpleTest_CFLAGS = -I$(top_builddir)/src -I$(top_builddir)/include
 __top_builddir__bin_simpleTest_SOURCES = simpleTest.c

+ 16 - 6
examples/src/opcuaServer.c

@@ -12,12 +12,22 @@
 #include <stdlib.h>
 
 #include "ua_stack.h"
+#include <pthread.h> // to get the type for the
 
+UA_Int32 serverCallback(void * arg) {
+	char *name = (char *) arg;
+	printf("%s does whatever servers do\n",name);
+	return UA_SUCCESS;
+}
+
+// necessary for the linker
+int pthread_create(pthread_t* newthread, const pthread_attr_t* attr, void *(*start) (void *), void * arg) {
+	perror("this routine should be never called in single-threaded mode\n");
+	exit(1);
+}
 
-int main(void) {
-	UA_Stack_init(&UA_TransportLayerDescriptorTcpBinary,16664);
-	while (UA_TRUE) {
-		sleep(10);
-	}
-	return EXIT_SUCCESS;
+int main(int argc, char** argv) {
+	struct timeval tv = {2, 0}; // 2 seconds
+	UA_Stack_init(&UA_TransportLayerDescriptorTcpBinary,16664,UA_STACK_SINGLETHREADED);
+	UA_Stack_msgLoop(&tv,serverCallback,argv[0]);
 }

+ 24 - 0
examples/src/opcuaServerMT.c

@@ -0,0 +1,24 @@
+/*
+ ============================================================================
+ Name        : opcuaServer.c
+ Author      :
+ Version     :
+ Copyright   : Your copyright notice
+ Description :
+ ============================================================================
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ua_stack.h"
+
+
+int main(int argc, char** argv) {
+	UA_Stack_init(&UA_TransportLayerDescriptorTcpBinary,16664,UA_STACK_MULTITHREADED);
+	while (UA_TRUE) {
+		printf("%s does whatever servers do\n",argv[0]);
+		sleep(2);
+	}
+	return EXIT_SUCCESS;
+}

+ 12 - 1
include/ua_stack.h

@@ -12,6 +12,9 @@
 #include "ua_connection.h"
 #include "ua_list.h"
 
+#include <pthread.h> // pthreadcreate, pthread_t
+#include <sys/select.h> // FD_ZERO, FD_SET
+
 #define UA_TL_MAXCONNECTIONS_DEFAULT 10
 
 enum UA_TRANSPORTLAYERDESCRIPTION_ENCODING_enum {
@@ -37,7 +40,15 @@ typedef struct T_UA_TL_data {
 	int listenerHandle;
 	pthread_t listenerThreadHandle;
 	UA_list_List connections;
+	UA_Int32 threaded;
+	fd_set readerHandles;
 } UA_TL_data;
 
-UA_Int32 UA_Stack_init(UA_TL_Description* tlDesc, UA_Int32 port);
+enum UA_STACK_THREADS_enum {
+	UA_STACK_SINGLETHREADED = 0,
+	UA_STACK_MULTITHREADED = 1,
+};
+
+UA_Int32 UA_Stack_init(UA_TL_Description* tlDesc, UA_Int32 port, UA_Int32 threaded);
+UA_Int32 UA_Stack_msgLoop(struct timeval* tv,UA_Int32 (*timeoutCallBack)(void*),void *arg);
 #endif /* UA_STACK_H_ */

+ 161 - 40
src/ua_stack.c

@@ -4,10 +4,11 @@
 #include <sys/socketvar.h>
 
 #include <unistd.h> // read, write, close
+#include <stdlib.h> // exit
 #include <errno.h> // errno, EINTR
 
 #include <memory.h> // memset
-#include <pthread.h>
+#include <fcntl.h> // fcntl
 
 #include "ua_stack.h"
 #include "ua_transportLayer.h"
@@ -19,42 +20,76 @@ UA_TL_Description UA_TransportLayerDescriptorTcpBinary  = {
 		{-1,8192,8192,16384,1}
 };
 
-// TODO: do we really need a variable global to the module?
+// TODO: We currently need a variable global to the module!
 UA_TL_data theTL;
 
-/** the tcp reader thread **/
+_Bool connectionComparer(void *p1, void* p2) {
+	UA_TL_connection* c1 = (UA_TL_connection*) p1;
+	UA_TL_connection* c2 = (UA_TL_connection*) p2;
+	return (c1->connectionHandle == c2->connectionHandle);
+}
+
+int UA_TL_TCP_SetNonBlocking(int sock) {
+	int opts = fcntl(sock,F_GETFL);
+	if (opts < 0) {
+		perror("fcntl(F_GETFL)");
+		return -1;
+	}
+	opts = (opts | O_NONBLOCK);
+	if (fcntl(sock,F_SETFL,opts) < 0) {
+		perror("fcntl(F_SETFL)");
+		return -1;
+	}
+	return 0;
+}
+
+/** the tcp reader thread - single shot if single-threaded, looping until CLOSE if multi-threaded
+ */
 void* UA_TL_TCP_reader(void *p) {
 	UA_TL_connection* c = (UA_TL_connection*) p;
 
 	UA_ByteString readBuffer;
 	UA_alloc((void**)&(readBuffer.data),c->localConf.recvBufferSize);
 
-	while (c->connectionState != connectionState_CLOSE) {
-		readBuffer.length = read(c->connectionHandle, readBuffer.data, c->localConf.recvBufferSize);
+	if (c->connectionState != connectionState_CLOSE) {
+		do {
+			printf("UA_TL_TCP_reader - enter read\n");
+			readBuffer.length = read(c->connectionHandle, readBuffer.data, c->localConf.recvBufferSize);
+			printf("UA_TL_TCP_reader - leave read\n");
 
-		printf("UA_TL_TCP_reader - %*.s ",c->remoteEndpointUrl.length,c->remoteEndpointUrl.data);
-		UA_ByteString_printx("received=",&readBuffer);
+			printf("UA_TL_TCP_reader - %*.s ",c->remoteEndpointUrl.length,c->remoteEndpointUrl.data);
+			UA_ByteString_printx("received=",&readBuffer);
 
-		if (readBuffer.length  > 0) {
-			TL_process(c,&readBuffer);
-		} else {
-			c->connectionState = connectionState_CLOSE;
-			perror("ERROR reading from socket1");
+			if (readBuffer.length  > 0) {
+				TL_process(c,&readBuffer);
+			} else {
+				c->connectionState = connectionState_CLOSE;
+				perror("ERROR reading from socket1");
+			}
+		} while (c->connectionState != connectionState_CLOSE && theTL.threaded == UA_STACK_MULTITHREADED);
+	}
+	if (c->connectionState == connectionState_CLOSE) {
+		// clean up: socket, buffer, connection
+		// free resources allocated with socket
+		if (theTL.threaded == UA_STACK_SINGLETHREADED) {
+			printf("UA_TL_TCP_reader - remove handle=%d from fd_set\n",c->connectionHandle);
+			// FD_CLR(c->connectionHandle,&(theTL.readerHandles));
 		}
+		printf("UA_TL_TCP_reader - shutdown\n");
+		printf("UA_TL_TCP_reader - enter shutdown\n");
+		shutdown(c->connectionHandle,2);
+		printf("UA_TL_TCP_reader - enter close\n");
+		close(c->connectionHandle);
+		printf("UA_TL_TCP_reader - leave close\n");
+		c->connectionState = connectionState_CLOSED;
+
+		UA_ByteString_deleteMembers(&readBuffer);
+		printf("UA_TL_TCP_reader - search element to remove\n");
+		UA_list_Element* lec = UA_list_search(&theTL.connections,connectionComparer,c);
+		printf("UA_TL_TCP_reader - remove handle=%d\n",((UA_TL_connection*)lec->payload)->connectionHandle);
+		UA_list_removeElement(lec,UA_NULL);
+		UA_free(c);
 	}
-	// clean up: socket, buffer, connection
-	// free resources allocated with socket
-	printf("UA_TL_TCP_reader - shutdown\n");
-	shutdown(c->connectionHandle,2);
-	close(c->connectionHandle);
-	c->connectionState = connectionState_CLOSED;
-	UA_ByteString_deleteMembers(&readBuffer);
-	// FIXME: standard C has no lambdas, we need a matcher with two arguments
-	// UA_list_Element* lec = UA_list_findFirst(theTL,c,compare);
-	// TODO: can we get get rid of reference to theTL?
-	UA_list_Element* lec = UA_list_find(&theTL.connections,UA_NULL);
-	UA_list_removeElement(lec,UA_NULL);
-	UA_free(c);
 	return UA_NULL;
 }
 
@@ -65,7 +100,9 @@ UA_Int32 UA_TL_TCP_write(struct T_TL_connection* c, UA_ByteString* msg) {
 	while (nWritten < msg->length) {
 		int n=0;
 		do {
+			printf("UA_TL_TCP_write - enter write\n");
 			n = write(c->connectionHandle, &(msg->data[nWritten]), msg->length-nWritten);
+			printf("UA_TL_TCP_write - leave write with n=%d,errno=%d\n",n,errno);
 		} while (n == -1L && errno == EINTR);
 		if (n >= 0) {
 			nWritten += n;
@@ -76,22 +113,33 @@ UA_Int32 UA_TL_TCP_write(struct T_TL_connection* c, UA_ByteString* msg) {
 	return UA_SUCCESS;
 }
 
-/** the tcp listener thread **/
+/** the tcp listener routine.
+ *  does a single shot if single threaded, runs forever if multithreaded
+ */
 void* UA_TL_TCP_listen(void *p) {
 	UA_TL_data* tld = (UA_TL_data*) p;
 
 	UA_String_printf("open62541-server at ",&(tld->endpointUrl));
-	while (UA_TRUE) {
-		listen(tld->listenerHandle, tld->tld->maxConnections);
+	do {
+		printf("UA_TL_TCP_listen - enter listen\n");
+		int retval = listen(tld->listenerHandle, tld->tld->maxConnections);
+		printf("UA_TL_TCP_listen - leave listen, retval=%d\n",retval);
 
-		// accept only if not max number of connections exceeded
-		if (tld->tld->maxConnections == -1 || tld->connections.size < tld->tld->maxConnections) {
+		if (retval < 0) {
+			// TODO: Error handling
+			printf("UA_TL_TCP_listen retval=%d, errno=%d\n",retval,errno);
+		} else if (tld->tld->maxConnections == -1 || tld->connections.size < tld->tld->maxConnections) {
+			// accept only if not max number of connections exceede
 			struct sockaddr_in cli_addr;
 			socklen_t cli_len = sizeof(cli_addr);
+			printf("UA_TL_TCP_listen - enter accept\n");
 			int newsockfd = accept(tld->listenerHandle, (struct sockaddr *) &cli_addr, &cli_len);
+			printf("UA_TL_TCP_listen - leave accept\n");
 			if (newsockfd < 0) {
+				printf("UA_TL_TCP_listen - accept returns errno=%d\n",errno);
 				perror("ERROR on accept");
 			} else {
+				printf("UA_TL_TCP_listen - new connection on %d\n",newsockfd);
 				UA_TL_connection* c;
 				UA_Int32 retval = UA_SUCCESS;
 				retval |= UA_alloc((void**)&c,sizeof(UA_TL_connection));
@@ -100,22 +148,90 @@ void* UA_TL_TCP_listen(void *p) {
 				c->UA_TL_writer = UA_TL_TCP_write;
 				// add to list
 				UA_list_addPayloadToBack(&(tld->connections),c);
-				// TODO: handle retval of pthread_create
-				pthread_create( &(c->readerThread), NULL, UA_TL_TCP_reader, (void*) c);
+				if (tld->threaded == UA_STACK_MULTITHREADED) {
+					// TODO: handle retval of pthread_create
+					pthread_create( &(c->readerThread), NULL, UA_TL_TCP_reader, (void*) c);
+				} else {
+					UA_TL_TCP_SetNonBlocking(c->connectionHandle);
+				}
 			}
 		} else {
 			// no action necessary to reject connection
 		}
-	}
+	} while (tld->threaded == UA_STACK_MULTITHREADED);
 	return UA_NULL;
 }
 
+void checkFdSet(void* payload) {
+  UA_TL_connection* c = (UA_TL_connection*) payload;
+  if (FD_ISSET(c->connectionHandle, &(theTL.readerHandles))) {
+	  UA_TL_TCP_reader((void*)c);
+  }
+}
+
+int maxHandle;
+void UA_TL_addHandleToSet(UA_Int32 handle) {
+	FD_SET(handle, &(theTL.readerHandles));
+	maxHandle = (handle > maxHandle) ? handle : maxHandle;
+}
+void setFdSet(void* payload) {
+  UA_TL_connection* c = (UA_TL_connection*) payload;
+  UA_TL_addHandleToSet(c->connectionHandle);
+}
+
+UA_Int32 UA_Stack_msgLoop(struct timeval *tv, UA_Int32(*worker)(void*), void *arg)  {
+	UA_Int32 result;
+	while (UA_TRUE) {
+		// determine the largest handle
+		maxHandle = 0;
+		UA_list_iteratePayload(&theTL.connections,setFdSet);
+		UA_TL_addHandleToSet(theTL.listenerHandle);
+		printf("UA_Stack_msgLoop - maxHandle=%d\n", maxHandle);
+
+		// copy tv, some unixes do overwrite and return the remaining time
+		struct timeval tmptv;
+		memcpy(&tmptv,tv,sizeof(struct timeval));
+
+		// and wait
+		printf("UA_Stack_msgLoop - enter select sec=%d,usec=%d\n",(UA_Int32) tmptv.tv_sec, (UA_Int32) tmptv.tv_usec);
+		result = select(maxHandle + 1, &(theTL.readerHandles), UA_NULL, UA_NULL,&tmptv);
+		printf("UA_Stack_msgLoop - leave select result=%d,sec=%d,usec=%d\n",result, (UA_Int32) tmptv.tv_sec, (UA_Int32) tmptv.tv_usec);
+		if (result == 0) {
+			int err = errno;
+			switch (err) {
+			case EBADF:
+				printf("UA_Stack_msgLoop - result=bad file\n"); //FIXME: handle
+				break;
+			case EINTR:
+				printf("UA_Stack_msgLoop - result=interupted\n"); //FIXME: handle
+				break;
+			case EINVAL:
+				printf("UA_Stack_msgLoop - result=bad arguments\n"); //FIXME: handle
+				break;
+			case EAGAIN:
+				printf("UA_Stack_msgLoop - result=do it again\n"); //FIXME: handle
+			default:
+				printf("UA_Stack_msgLoop - result=%d\n",err); //FIXME: handle
+				worker(arg);
+			}
+		} else if (FD_ISSET(theTL.listenerHandle,&theTL.readerHandles)) { // activity on listener port
+			printf("UA_Stack_msgLoop - connection request\n");
+			UA_TL_TCP_listen((void*)&theTL);
+		} else { // activity on client ports
+			printf("UA_Stack_msgLoop - activities on %d handles\n",result);
+			UA_list_iteratePayload(&theTL.connections,checkFdSet);
+		}
+	}
+	return UA_SUCCESS;
+}
+
 UA_Int32 UA_TL_TCP_init(UA_TL_data* tld, UA_Int32 port) {
 	UA_Int32 retval = UA_SUCCESS;
 	// socket variables
 	int optval = 1;
 	struct sockaddr_in serv_addr;
 
+
 	// create socket for listening to incoming connections
 	tld->listenerHandle = socket(PF_INET, SOCK_STREAM, 0);
 	if (tld->listenerHandle < 0) {
@@ -127,8 +243,7 @@ UA_Int32 UA_TL_TCP_init(UA_TL_data* tld, UA_Int32 port) {
 		serv_addr.sin_family = AF_INET;
 		serv_addr.sin_addr.s_addr = INADDR_ANY;
 		serv_addr.sin_port = htons(port);
-		if (setsockopt(tld->listenerHandle, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval)
-				== -1) {
+		if (setsockopt(tld->listenerHandle, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) == -1 ) {
 			perror("setsockopt");
 			retval = UA_ERROR;
 		} else {
@@ -145,17 +260,23 @@ UA_Int32 UA_TL_TCP_init(UA_TL_data* tld, UA_Int32 port) {
 	}
 	// finally
 	if (retval == UA_SUCCESS) {
-		// TODO: handle retval of pthread_create
-		pthread_create( &tld->listenerThreadHandle, NULL, UA_TL_TCP_listen, (void*) tld);
+		if (tld->threaded == UA_STACK_MULTITHREADED) {
+			// TODO: handle retval of pthread_create
+			pthread_create( &tld->listenerThreadHandle, NULL, UA_TL_TCP_listen, (void*) tld);
+		} else {
+			UA_TL_TCP_SetNonBlocking(tld->listenerHandle);
+			FD_ZERO(&(tld->readerHandles));
+		}
 	}
 	return retval;
 }
 
 /** checks arguments and dispatches to worker or refuses to init */
-UA_Int32 UA_TL_init(UA_TL_Description* tlDesc, UA_Int32 port) {
+UA_Int32 UA_TL_init(UA_TL_Description* tlDesc, UA_Int32 port, UA_Int32 threaded) {
 	UA_Int32 retval = UA_SUCCESS;
 	if (tlDesc->connectionType == UA_TL_CONNECTIONTYPE_TCPV4 && tlDesc->encoding == UA_TL_ENCODING_BINARY) {
 		theTL.tld = tlDesc;
+		theTL.threaded = threaded;
 		UA_list_init(&theTL.connections);
 		retval |= UA_TL_TCP_init(&theTL,port);
 	} else {
@@ -165,8 +286,8 @@ UA_Int32 UA_TL_init(UA_TL_Description* tlDesc, UA_Int32 port) {
 }
 
 /** checks arguments and dispatches to worker or refuses to init */
-UA_Int32 UA_Stack_init(UA_TL_Description* tlDesc, UA_Int32 port) {
+UA_Int32 UA_Stack_init(UA_TL_Description* tlDesc, UA_Int32 port, UA_Int32 threaded) {
 	UA_Int32 retval = UA_SUCCESS;
-	retval = UA_TL_init(tlDesc,port);
+	retval = UA_TL_init(tlDesc,port,threaded);
 	return retval;
 }

+ 0 - 212
tests/check_calcSize.c

@@ -1,212 +0,0 @@
-/*
- ============================================================================
- Name        : check_calcsize.c
- Author      :
- Version     :
- Copyright   : Your copyright notice
- Description :
- ============================================================================
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "opcua.h"
-#include "ua_transportLayer.h"
-#include "check.h"
-
-
-START_TEST(diagnosticInfo_calcSize_test)
-{
-
-	UA_Int32 valreal = 0;
-	UA_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;
-
-	ck_assert_int_eq(UA_DiagnosticInfo_calcSize(&diagnosticInfo),26);
-
-}
-END_TEST
-
-START_TEST(extensionObject_calcSize_test)
-{
-
-	UA_Int32 valreal = 0;
-	UA_Int32 valcalc = 0;
-	UA_Byte data[3] = {1,2,3};
-	UA_ExtensionObject extensionObject;
-
-	// empty ExtensionObject, handcoded
-	extensionObject.typeId.encodingByte = UA_NODEIDTYPE_TWOBYTE;
-	extensionObject.typeId.identifier.numeric = 0;
-	extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_NOBODYISENCODED;
-	ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 1 + 1 + 1);
-
-	// ExtensionObject with ByteString-Body
-	extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_BODYISBYTESTRING;
-	extensionObject.body.data = data;
-	extensionObject.body.length = 3;
-	ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 3 + 4 + 3);
-}
-END_TEST
-
-START_TEST(responseHeader_calcSize_test)
-{
-	UA_ResponseHeader responseHeader;
-	UA_DiagnosticInfo diagnosticInfo;
-	UA_ExtensionObject extensionObject;
-	UA_DiagnosticInfo  emptyDO = {0x00};
-	UA_ExtensionObject emptyEO = {{UA_NODEIDTYPE_TWOBYTE,0},UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_NOBODYISENCODED};
-	//Should have the size of 26 Bytes
-	diagnosticInfo.encodingMask = UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_SYMBOLICID | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_NAMESPACE | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_LOCALIZEDTEXT | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_LOCALE | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_ADDITIONALINFO;		// 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
-	// Additional Info
-	diagnosticInfo.additionalInfo.length = 5;							// Int32:  4
-	diagnosticInfo.additionalInfo.data = "OPCUA";						// Byte[]: 5
-	responseHeader.serviceDiagnostics = &diagnosticInfo;
-	ck_assert_int_eq(UA_DiagnosticInfo_calcSize(&diagnosticInfo),1+(4+4+4+4)+(4+5));
-
-	responseHeader.stringTableSize = -1;								// Int32:	4
-	responseHeader.stringTable = NULL;
-
-	responseHeader.additionalHeader = &emptyEO;	//		    3
-	ck_assert_int_eq(UA_ResponseHeader_calcSize(&responseHeader),16+26+4+3);
-
-	responseHeader.serviceDiagnostics = &emptyDO;
-	ck_assert_int_eq(UA_ResponseHeader_calcSize(&responseHeader),16+1+4+3);
-}
-END_TEST
-
-//ToDo: Function needs to be filled
-START_TEST(expandedNodeId_calcSize_test)
-{
-	UA_Int32 valreal = 300;
-	UA_Int32 valcalc = 0;
-	ck_assert_int_eq(valcalc,valreal);
-}
-END_TEST
-START_TEST(DataValue_calcSize_test)
-{
-	UA_DataValue dataValue;
-	dataValue.encodingMask = UA_DATAVALUE_STATUSCODE |  UA_DATAVALUE_SOURCETIMESTAMP |  UA_DATAVALUE_SOURCEPICOSECONDS;
-	dataValue.status = 12;
-	UA_DateTime dateTime;
-	dateTime = 80;
-	dataValue.sourceTimestamp = dateTime;
-	UA_DateTime sourceTime;
-	dateTime = 214;
-	dataValue.sourcePicoseconds = sourceTime;
-
-	int size = 0;
-	size = UA_DataValue_calcSize(&dataValue);
-
-	ck_assert_int_eq(size, 21);
-}
-END_TEST
-
-Suite* testSuite_diagnosticInfo_calcSize()
-{
-	Suite *s = suite_create("diagnosticInfo_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, diagnosticInfo_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite* testSuite_extensionObject_calcSize()
-{
-	Suite *s = suite_create("extensionObject_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, extensionObject_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite* testSuite_responseHeader_calcSize()
-{
-	Suite *s = suite_create("responseHeader_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, responseHeader_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite* testSuite_dataValue_calcSize(void)
-{
-	Suite *s = suite_create("dataValue_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core,DataValue_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite* testSuite_expandedNodeId_calcSize(void)
-{
-	Suite *s = suite_create("expandedNodeId_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core,expandedNodeId_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-int main (void)
-{
-	int number_failed = 0;
-
-	Suite *s = testSuite_diagnosticInfo_calcSize();
-	SRunner *sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	s = testSuite_extensionObject_calcSize();
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	s = testSuite_responseHeader_calcSize();
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	s = testSuite_expandedNodeId_calcSize();
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	s = testSuite_dataValue_calcSize();
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	s = testSuite_expandedNodeId_calcSize();
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	s = testSuite_dataValue_calcSize();
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	/* <TESTSUITE_TEMPLATE>
-	s =  <TESTSUITENAME>;
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-	*/
-	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}

+ 0 - 904
tests/check_generated.c

@@ -1,904 +0,0 @@
-/*
- ============================================================================
- Name        : check_stack.c
- Author      :
- Version     :
- Copyright   : Your copyright notice
- Description :
- ============================================================================
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "opcua.h"
-#include "check.h"
-
-START_TEST(UA_Byte_decode_test)
-{
-	UA_Byte dst;
-	UA_Byte src[] = { 0x08 };
-	UA_Int32 retval, pos = 0;
-
-	retval = UA_Byte_decode(src, &pos, &dst);
-
-	ck_assert_int_eq(retval, UA_SUCCESS);
-	ck_assert_uint_eq(pos, 1);
-	ck_assert_uint_eq(dst, 8);
-}
-END_TEST
-
-START_TEST(UA_Byte_encode_test)
-{
-	UA_Byte src;
-	UA_Byte dst[2] = { 0x00, 0xFF };
-	UA_Int32 retval, pos = 0;
-
-	ck_assert_uint_eq(dst[1], 0xFF);
-
-	src = 8;
-	retval = UA_Byte_encode(&src, &pos, dst);
-
-	ck_assert_uint_eq(dst[0], 0x08);
-	ck_assert_uint_eq(dst[1], 0xFF);
-	ck_assert_int_eq(pos, 1);
-	ck_assert_int_eq(retval, UA_SUCCESS);
-
-	src = 0xFF;
-	dst[1] = 0x00;
-	pos = 0;
-	retval = UA_Byte_encode(&src, &pos, dst);
-
-	ck_assert_int_eq(dst[0], 0xFF);
-	ck_assert_int_eq(dst[1], 0x00);
-	ck_assert_int_eq(pos, 1);
-	ck_assert_int_eq(retval, UA_SUCCESS);
-
-}
-END_TEST
-
-START_TEST(UA_Int16_decode_test_positives)
-{
-	UA_Int32 p = 0;
-	UA_Int16 val;
-	UA_Int32 retval;
-	UA_Byte buf[] = {
-			0x00,0x00,	// 0
-			0x01,0x00,	// 1
-			0xFF,0x00,	// 255
-			0x00,0x01,	// 256
-	};
-
-	retval = UA_Int16_decode(buf,&p,&val);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(val,0);
-	retval = UA_Int16_decode(buf,&p,&val);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(val,1);
-	retval = UA_Int16_decode(buf,&p,&val);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(val,255);
-	retval = UA_Int16_decode(buf,&p,&val);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(val,256);
-}
-END_TEST
-START_TEST(UA_Int16_decode_test_negatives)
-{
-	UA_Int32 p = 0;
-	UA_Int16 val;
-	UA_Int32 retval;
-	UA_Byte mem[] = {
-			0xFF,0xFF,	// -1
-			0x00,0x80,	// -32768
-	};
-
-
-	retval = UA_Int16_decode(mem,&p,&val);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(val,-1);
-	retval = UA_Int16_decode(mem,&p,&val);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(val,-32768);
-}
-END_TEST
-
-/*
-START_TEST(decodeRequestHeader_test_validParameter)
-{
-		char testMessage = {0x00,0x00,0x72,0xf1,0xdc,0xc9,0x87,0x0b,
-
-							0xcf,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
-							0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,
-							0x00,0x00,0x00,0x00,0x00};
-		AD_RawMessage rawMessage;
-		rawMessage.message = &testMessage;
-		rawMessage.length = 29;
-		Int32 position = 0;
-		T_RequestHeader requestHeader;
-		decodeRequestHeader(rawMessage,&position,&requestHeader);
-
-		ck_assert_int_eq(requestHeader.authenticationToken.EncodingByte,0);
-
-		ck_assert_int_eq(requestHeader.returnDiagnostics,0);
-
-		ck_assert_int_eq(requestHeader.authenticationToken.EncodingByte,0);
-
-}
-END_TEST
-
-
-
-START_TEST(encodeInt16_test)
-{
-
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	//EncodeUInt16
-	char *mem = malloc(sizeof(UInt16));
-	rawMessage.message = mem;
-	UInt16 testUInt16 = 1;
-	rawMessage.length = 2;
-	position = 0;
-
-	encodeUInt16(testUInt16, &position, rawMessage.message);
-	//encodeUInt16(testUInt16, &position, &rawMessage);
-
-	ck_assert_int_eq(position, 2);
-	Int32 p = 0;
-	Int16 val;
-	decoder_decodeBuiltInDatatype(rawMessage.message, INT16, &p, &val);
-	ck_assert_int_eq(val,testUInt16);
-	//ck_assert_int_eq(rawMessage.message[0], 0xAB);
-
-}
-END_TEST
-
-START_TEST(decodeUInt16_test)
-{
-
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	//EncodeUInt16
-	char mem[2] = {0x01,0x00};
-
-	rawMessage.message = mem;
-
-	rawMessage.length = 2;
-
-	//encodeUInt16(testUInt16, &position, &rawMessage);
-
-	Int32 p = 0;
-	UInt16 val;
-	decoder_decodeBuiltInDatatype(rawMessage.message,UINT16,&p,&val);
-
-	ck_assert_int_eq(val,1);
-	//ck_assert_int_eq(p, 2);
-	//ck_assert_int_eq(rawMessage.message[0], 0xAB);
-
-}
-END_TEST
-START_TEST(encodeUInt16_test)
-{
-
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	//EncodeUInt16
-	char *mem = malloc(sizeof(UInt16));
-	rawMessage.message = mem;
-	UInt16 testUInt16 = 1;
-	rawMessage.length = 2;
-	position = 0;
-
-	encodeUInt16(testUInt16, &position, rawMessage.message);
-	//encodeUInt16(testUInt16, &position, &rawMessage);
-
-	ck_assert_int_eq(position, 2);
-	Int32 p = 0;
-	UInt16 val;
-	decoder_decodeBuiltInDatatype(rawMessage.message, UINT16, &p, &val);
-	ck_assert_int_eq(val,testUInt16);
-	//ck_assert_int_eq(rawMessage.message[0], 0xAB);
-
-}
-END_TEST
-
-
-START_TEST(decodeUInt32_test)
-{
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	//EncodeUInt16
-	char mem[4] = {0xFF,0x00,0x00,0x00};
-
-	rawMessage.message = mem;
-	rawMessage.length = 4;
-
-	Int32 p = 0;
-	UInt32 val;
-	decoder_decodeBuiltInDatatype(rawMessage.message, UINT32, &p, &val);
-	ck_assert_uint_eq(val,255);
-
-}
-END_TEST
-START_TEST(encodeUInt32_test)
-{
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	UInt32 value = 0x0101FF00;
-	//EncodeUInt16
-
-	rawMessage.message = (char*)opcua_malloc(2 * sizeof(UInt32));
-
-	rawMessage.length = 8;
-
-	Int32 p = 4;
-	//encodeUInt32(value, &p,rawMessage.message);
-	encoder_encodeBuiltInDatatype(&value,UINT32,&p,rawMessage.message);
-	ck_assert_uint_eq((Byte)rawMessage.message[4],0x00);
-	ck_assert_uint_eq((Byte)rawMessage.message[5],0xFF);
-	ck_assert_uint_eq((Byte)rawMessage.message[6],0x01);
-	ck_assert_uint_eq((Byte)rawMessage.message[7],0x01);
-	ck_assert_int_eq(p,8);
-
-
-}
-END_TEST
-
-START_TEST(decodeInt32_test)
-{
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	//EncodeUInt16
-	char mem[4] = {0x00,0xCA,0x9A,0x3B};
-
-	rawMessage.message = mem;
-
-	rawMessage.length = 4;
-
-
-	Int32 p = 0;
-	Int32 val;
-	decoder_decodeBuiltInDatatype(rawMessage.message, INT32, &p, &val);
-	ck_assert_int_eq(val,1000000000);
-}
-END_TEST
-START_TEST(encodeInt32_test)
-{
-
-}
-END_TEST
-
-
-START_TEST(decodeUInt64_test)
-{
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	UInt64 expectedVal = 0xFF;
-	expectedVal = expectedVal << 56;
-	char mem[8] = {00,00,00,00,0x00,0x00,0x00,0xFF};
-
-	rawMessage.message = mem;
-
-	rawMessage.length = 8;
-
-	Int32 p = 0;
-	UInt64 val;
-	decoder_decodeBuiltInDatatype(rawMessage.message, UINT64, &p, &val);
-	ck_assert_uint_eq(val, expectedVal);
-}
-END_TEST
-START_TEST(encodeUInt64_test)
-{
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	UInt64 value = 0x0101FF00FF00FF00;
-	//EncodeUInt16
-
-	rawMessage.message = (char*)opcua_malloc(sizeof(UInt32));
-
-	rawMessage.length = 8;
-
-	Int32 p = 0;
-	encodeUInt64(value, &p,rawMessage.message);
-
-	ck_assert_uint_eq((Byte)rawMessage.message[0],0x00);
-	ck_assert_uint_eq((Byte)rawMessage.message[1],0xFF);
-	ck_assert_uint_eq((Byte)rawMessage.message[2],0x00);
-	ck_assert_uint_eq((Byte)rawMessage.message[3],0xFF);
-	ck_assert_uint_eq((Byte)rawMessage.message[4],0x00);
-	ck_assert_uint_eq((Byte)rawMessage.message[5],0xFF);
-	ck_assert_uint_eq((Byte)rawMessage.message[6],0x01);
-	ck_assert_uint_eq((Byte)rawMessage.message[7],0x01);
-}
-END_TEST
-
-START_TEST(decodeInt64_test)
-{
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	Int64 expectedVal = 0xFF;
-	expectedVal = expectedVal << 56;
-	char mem[8] = {00,00,00,00,0x00,0x00,0x00,0xFF};
-
-	rawMessage.message = mem;
-
-	rawMessage.length = 8;
-
-	Int32 p = 0;
-	Int64 val;
-	decoder_decodeBuiltInDatatype(rawMessage.message, INT64, &p, &val);
-	ck_assert_uint_eq(val, expectedVal);
-}
-END_TEST
-START_TEST(encodeInt64_test)
-{
-	AD_RawMessage rawMessage;
-	Int32 position = 0;
-	UInt64 value = 0x0101FF00FF00FF00;
-	//EncodeUInt16
-
-	rawMessage.message = (char*)opcua_malloc(sizeof(UInt32));
-
-	rawMessage.length = 8;
-
-	Int32 p = 0;
-	encodeUInt64(value, &p,rawMessage.message);
-
-	ck_assert_uint_eq((Byte)rawMessage.message[0],0x00);
-	ck_assert_uint_eq((Byte)rawMessage.message[1],0xFF);
-	ck_assert_uint_eq((Byte)rawMessage.message[2],0x00);
-	ck_assert_uint_eq((Byte)rawMessage.message[3],0xFF);
-	ck_assert_uint_eq((Byte)rawMessage.message[4],0x00);
-	ck_assert_uint_eq((Byte)rawMessage.message[5],0xFF);
-	ck_assert_uint_eq((Byte)rawMessage.message[6],0x01);
-	ck_assert_uint_eq((Byte)rawMessage.message[7],0x01);
-}
-END_TEST
-
-
-START_TEST(decodeFloat_test)
-{
-	Float expectedValue = -6.5;
-	Int32 pos = 0;
-	char buf[4] = {0x00,0x00,0xD0,0xC0};
-
-
-	Float calcVal;
-
-	decoder_decodeBuiltInDatatype(buf, FLOAT, &pos, &calcVal);
-	//val should be -6.5
-
-	Int32 val = (calcVal > -6.501 && calcVal < -6.499);
-
-
-	ck_assert_int_gt(val,0);
-
-	opcua_free(buf);
-}
-END_TEST
-START_TEST(encodeFloat_test)
-{
-	Float value = -6.5;
-	Int32 pos = 0;
-	char *buf = (char*)opcua_malloc(sizeof(Float));
-
-	encodeFloat(value,&pos,buf);
-
-	ck_assert_uint_eq((Byte)buf[2],0xD0);
-	ck_assert_uint_eq((Byte)buf[3],0xC0);
-	opcua_free(buf);
-
-}
-END_TEST
-
-START_TEST(decodeDouble_test)
-{
-
-}
-END_TEST
-START_TEST(encodeDouble_test)
-{
-	Float value = -6.5;
-	Int32 pos = 0;
-	char *buf = (char*)opcua_malloc(sizeof(Float));
-
-	encodeDouble(value,&pos,buf);
-
-	ck_assert_uint_eq((Byte)buf[6],0xD0);
-	ck_assert_uint_eq((Byte)buf[7],0xC0);
-	opcua_free(buf);
-}
-END_TEST
-
-
-START_TEST(encodeUAString_test)
-{
-
-	Int32 pos = 0;
-	UA_String string;
-	Int32 l = 11;
-	char mem[11] = "ACPLT OPCUA";
-	char *dstBuf = (char*) malloc(sizeof(Int32)+l);
-	string.Data =  mem;
-	string.Length = 11;
-
-	encodeUAString(&string, &pos, dstBuf);
-
-	ck_assert_int_eq(dstBuf[0],11);
-	ck_assert_int_eq(dstBuf[0+sizeof(Int32)],'A');
-
-
-}
-END_TEST
-START_TEST(decodeUAString_test)
-{
-
-	Int32 pos = 0;
-	UA_String string;
-	Int32 l = 11;
-	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;
-	decodeUAString(binString, &pos, &string);
-
-
-	ck_assert_int_eq(string.Length,11);
-	ck_assert_int_eq(string.Data[3],'L');
-
-
-}
-END_TEST
-
-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;
-
-	valcalc = diagnosticInfo_calcSize(&diagnosticInfo);
-	valreal = 26;
-	ck_assert_int_eq(valcalc,valreal);
-
-}
-END_TEST
-
-START_TEST(extensionObject_calcSize_test)
-{
-
-	Int32 valreal = 0;
-	Int32 valcalc = 0;
-	Byte data[3] = {1,2,3};
-	UA_ExtensionObject extensionObject;
-
-	// empty ExtensionObject
-	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;
-	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;
-	ck_assert_int_eq(extensionObject_calcSize(&extensionObject), 3 + 4 + 3);
-
-}
-END_TEST
-
-START_TEST(responseHeader_calcSize_test)
-{
-	UA_AD_ResponseHeader responseHeader;
-	UA_DiagnosticInfo diagnosticInfo;
-	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
-	// 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
-	// Additional Info
-	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));
-
-	responseHeader.noOfStringTable = -1;								// Int32:	4
-	responseHeader.stringTable = NULL;
-
-	responseHeader.additionalHeader = &the_empty_UA_ExtensionObject;	//		    3
-	ck_assert_int_eq(responseHeader_calcSize(&responseHeader),16+26+4+3);
-
-	responseHeader.serviceDiagnostics = &the_empty_UA_DiagnosticInfo;
-	ck_assert_int_eq(responseHeader_calcSize(&responseHeader),16+1+4+3);
-}
-END_TEST
-
-//ToDo: Function needs to be filled
-START_TEST(expandedNodeId_calcSize_test)
-{
-	Int32 valreal = 300;
-	Int32 valcalc = 0;
-	ck_assert_int_eq(valcalc,valreal);
-}
-END_TEST
-
-START_TEST(encodeDataValue_test)
-{
-	UA_DataValue dataValue;
-	Int32 pos = 0;
-	char *buf = (char*)opcua_malloc(15);
-	UA_DateTime dateTime;
-	dateTime = 80;
-	dataValue.ServerTimestamp = dateTime;
-
-	//--without Variant
-	dataValue.EncodingMask = 0x08; //Only the SourvePicoseconds
-	encodeDataValue(&dataValue, &pos, buf);
-
-	ck_assert_int_eq(pos, 9);// represents the length
-	ck_assert_int_eq(buf[0], 0x08);
-	ck_assert_int_eq(buf[1], 80);
-	ck_assert_int_eq(buf[2], 0);
-	ck_assert_int_eq(buf[3], 0);
-	ck_assert_int_eq(buf[4], 0);
-	ck_assert_int_eq(buf[5], 0);
-	ck_assert_int_eq(buf[6], 0);
-	ck_assert_int_eq(buf[7], 0);
-	ck_assert_int_eq(buf[8], 0);
-
-	//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
-	UA_Variant variant;
-	variant.ArrayLength = 0;
-	variant.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;
-	encodeDataValue(&dataValue, &pos, buf);
-
-	ck_assert_int_eq(pos, 14);// represents the length
-	ck_assert_int_eq(buf[0], 0x08);
-	ck_assert_int_eq(buf[1], 0x06);
-	ck_assert_int_eq(buf[2], 45);
-	ck_assert_int_eq(buf[3], 0);
-	ck_assert_int_eq(buf[4], 0);
-	ck_assert_int_eq(buf[5], 0);
-	ck_assert_int_eq(buf[6], 80);
-	ck_assert_int_eq(buf[7], 0);
-
-}
-END_TEST
-
-START_TEST(DataValue_calcSize_test)
-{
-	UA_DataValue dataValue;
-	dataValue.EncodingMask = 0x02 + 0x04 + 0x10;
-	dataValue.Status = 12;
-	UA_DateTime dateTime;
-	dateTime = 80;
-	dataValue.SourceTimestamp = dateTime;
-	UA_DateTime sourceTime;
-	dateTime = 214;
-	dataValue.SourcePicoseconds = sourceTime;
-
-	int size = 0;
-	size = DataValue_calcSize(&dataValue);
-
-	ck_assert_int_eq(size, 21);
-}
-END_TEST
-
-START_TEST(encode_builtInDatatypeArray_test_String)
-{
-	Int32 noElements = 2;
-	UA_ByteString s1 = { 6, "OPC UA" };
-	UA_ByteString s2 = { -1, NULL };
-	UA_ByteString* array[] = { &s1, &s2	};
-	Int32 pos = 0, i;
-	char buf[256];
-	char result[] = {
-			0x02, 0x00, 0x00, 0x00,		// noElements
-			0x06, 0x00, 0x00, 0x00,		// s1.Length
-			'O', 'P', 'C', ' ', 'U', 'A', // s1.Data
-			0xFF, 0xFF, 0xFF, 0xFF		// s2.Length
-	};
-
-	encoder_encodeBuiltInDatatypeArray(array, noElements, BYTE_STRING, &pos, buf);
-
-	// check size
-	ck_assert_int_eq(pos, 4 + 4 + 6 + 4);
-	// check result
-	for (i=0; i< sizeof(result); i++) {
-		ck_assert_int_eq(buf[i],result[i]);
-	}
-}
-END_TEST
-
-Suite *testSuite_getPacketType(void)
-{
-	Suite *s = suite_create("getPacketType");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core,test_getPacketType_validParameter);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-*/
-
-Suite *testSuite_basicTypes(void)
-{
-	Suite *s = suite_create("basic types");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, UA_Byte_decode_test);
-	tcase_add_test(tc_core, UA_Byte_encode_test);
-	tcase_add_test(tc_core, UA_Int16_decode_test_negatives);
-	tcase_add_test(tc_core, UA_Int16_decode_test_positives);
-	tcase_add_test(tc_core, UA_Byte_encode_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-
-/*
-Suite *testSuite_decodeInt16(void)
-{
-	Suite *s = suite_create("decodeInt16_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeInt16_test_positives);
-	tcase_add_test(tc_core, decodeInt16_test_negatives);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite*testSuite_encodeInt16(void)
-{
-	Suite *s = suite_create("encodeInt16_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeInt16_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-
-Suite *testSuite_decodeUInt16(void)
-{
-	Suite *s = suite_create("decodeUInt16_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeUInt16_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite*testSuite_encodeUInt16(void)
-{
-	Suite *s = suite_create("encodeUInt16_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeUInt16_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite*testSuite_decodeUInt32(void)
-{
-	Suite *s = suite_create("decodeUInt32_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeUInt32_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite*testSuite_encodeUInt32(void)
-{
-	Suite *s = suite_create("encodeUInt32_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeUInt32_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite*testSuite_decodeInt32(void)
-{
-	Suite *s = suite_create("decodeInt32_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeInt32_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite*testSuite_encodeInt32(void)
-{
-	Suite *s = suite_create("encodeInt32_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeInt32_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-
-
-
-Suite*testSuite_decodeUInt64(void)
-{
-	Suite *s = suite_create("decodeUInt64_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeUInt64_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite*testSuite_encodeUInt64(void)
-{
-	Suite *s = suite_create("encodeUInt64_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeUInt64_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite*testSuite_decodeInt64(void)
-{
-	Suite *s = suite_create("decodeInt64_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeInt64_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite*testSuite_encodeInt64(void)
-{
-	Suite *s = suite_create("encodeInt64_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeInt64_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite *testSuite_encodeFloat(void)
-{
-	Suite *s = suite_create("encodeFloat_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeFloat_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite *testSuite_decodeFloat(void)
-{
-	Suite *s = suite_create("decodeFloat_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeFloat_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite *testSuite_encodeDouble(void)
-{
-	Suite *s = suite_create("encodeDouble_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeDouble_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite *testSuite_decodeDouble(void)
-{
-	Suite *s = suite_create("decodeDouble_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeDouble_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite * testSuite_encodeUAString(void)
-{
-	Suite *s = suite_create("encodeUAString_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeUAString_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite * testSuite_decodeUAString(void)
-{
-	Suite *s = suite_create("decodeUAString_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, decodeUAString_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite* testSuite_encodeDataValue()
-{
-	Suite *s = suite_create("encodeDataValue");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encodeDataValue_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite* testSuite_encode_builtInDatatypeArray()
-{
-	Suite *s = suite_create("encode_builtInDatatypeArray");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, encode_builtInDatatypeArray_test_String);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite* testSuite_expandedNodeId_calcSize(void)
-{
-	Suite *s = suite_create("expandedNodeId_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core,expandedNodeId_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-Suite* testSuite_diagnosticInfo_calcSize()
-{
-	Suite *s = suite_create("diagnosticInfo_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, diagnosticInfo_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite* testSuite_extensionObject_calcSize()
-{
-	Suite *s = suite_create("extensionObject_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, extensionObject_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite* testSuite_responseHeader_calcSize()
-{
-	Suite *s = suite_create("responseHeader_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, responseHeader_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-Suite* testSuite_dataValue_calcSize(void)
-{
-	Suite *s = suite_create("dataValue_calcSize");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core,DataValue_calcSize_test);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-*/
-
-/*
-Suite* TL_<TESTSUITENAME>(void)
-{
-	Suite *s = suite_create("<TESTSUITENAME>");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core,<TEST_NAME>);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-*/
-
-int main (void)
-{
-	int number_failed = 0;
-	Suite* s;
-	SRunner*  sr;
-
-	s = testSuite_basicTypes();
-	sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
-