Browse Source

added another testcase for variant (multidimensional array), perhaps accessing functions for md arrays are needed

FlorianPalm 10 years ago
parent
commit
36ab086861
3 changed files with 55 additions and 76 deletions
  1. 19 33
      examples/src/opcuaServerACPLT.c
  2. 5 5
      src/ua_basictypes.c
  3. 31 38
      tests/check_builtin.c

+ 19 - 33
examples/src/opcuaServerACPLT.c

@@ -70,34 +70,29 @@ void tmpTestFunction()
 	UA_Variant *value = UA_NULL;
 	UA_Variant *copiedValue = UA_NULL;
 	UA_Int32 **dimensions;
-	UA_Int32 i,j,i1,i2;
+	UA_Int32 i,i1,i2;
 	UA_Int32 **srcArray;
-	UA_Int32 **dstArray;
-	UA_Array_new((void***)&srcArray,9,UA_INT32);
-
-	//1st line
-	srcArray[0][0] = 0;
-	srcArray[1][0] = 1;
-	srcArray[2][0] = 2;
-	srcArray[0][1] = 3;
-	//2nd line
-	srcArray[0][1] = 4;
-	srcArray[1][1] = 5;
-	srcArray[2][1] = 6;
-	//3rd line
-	srcArray[0][2] = 7;
-	srcArray[1][2] = 8;
-	srcArray[2][2] = 9;
+	UA_Array_new((void***)&srcArray,6,UA_INT32);
+
+
+	*srcArray[0] = 0;
+	*srcArray[1] = 1;
+	*srcArray[2] = 2;
+	*srcArray[3] = 3;
+	*srcArray[4] = 4;
+	*srcArray[5] = 5;
+
+
 
 	UA_Array_new((void***)&dimensions,2,UA_INT32);
 
 	*(dimensions)[0] = 3;
-	*(dimensions)[1] = 3;
+	*(dimensions)[1] = 2;
 
 	UA_Variant_new(&value);
 	UA_Variant_new(&copiedValue);
 
-	value->arrayLength = 9;
+	value->arrayLength = 6;
 	value->data = (void**)srcArray;
 	value->arrayDimensionsLength = 2;
 	value->arrayDimensions = dimensions;
@@ -112,28 +107,19 @@ void tmpTestFunction()
 	//1st dimension
 	i1 = *(value->arrayDimensions)[0],
 	i2 = *(copiedValue->arrayDimensions)[0];
-//	ck_assert_int_eq(i1,i2);
-
+	//	ck_assert_int_eq(i1,i2);
 
 	//2nd dimension
-	i1 = (value->arrayDimensions)[1][0],
-	i2 = (copiedValue->arrayDimensions)[1][0];
+	i1 = *(value->arrayDimensions)[1];
+	i2 = *(copiedValue->arrayDimensions)[1];
 	//ck_assert_int_eq(i1,i2);
 
-	for(i=0;i<9;i++){
+	for(i=0;i<6;i++){
 		i1 = *((UA_Int32*)(value->data[i]));
 		i2 = *((UA_Int32*)(copiedValue->data[i]));
 	//	ck_assert_int_eq(i1,i2);
 	}
-	dstArray = ((UA_Int32**)(copiedValue->data));
-	for(i=0;i<3;i++){
-		for(j=0;j<3;j++){
-			i1 = srcArray[j][i];
-			i2 = dstArray[j][i];
-		//	ck_assert_int_eq(i1,i2);
-		}
-	}
-	i1 = i2 * i1;
+
 }
 void server_run() {
 	//just for debugging

+ 5 - 5
src/ua_basictypes.c

@@ -115,6 +115,7 @@ UA_Int32 UA_Array_copy(void const * const * src, UA_Int32 noElements, UA_Int32 t
 	// Get memory for the pointers
 	CHECKED_DECODE(UA_Array_new(dst, noElements, type), dst = UA_NULL;);
 	void **arr = *dst;
+	//void *srcArr = *src;
 
 	//only namespace zero types atm
 	if(UA_VTable_isValidType(type) != UA_SUCCESS)
@@ -1034,6 +1035,7 @@ UA_Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject const * p) {
 	}
 	return length;
 }
+
 UA_TYPE_START_ENCODEBINARY(UA_ExtensionObject)
 	retval |= UA_NodeId_encodeBinary(&(src->typeId),pos,dst);
 	retval |= UA_Byte_encodeBinary(&(src->encoding),pos,dst);
@@ -1516,15 +1518,13 @@ UA_Int32 UA_Variant_copy(UA_Variant const *src, UA_Variant *dst)
 		retval |=  UA_Array_copy((const void * const *)(src->data),src->arrayLength, uaIdx,(void***)&(dst->data));
 	}
 	else {
-
-		UA_alloc((void**)&pData,UA_[UA_toIndex(ns0Id)].calcSize(UA_NULL));
+		UA_alloc((void**)&pData,UA_[uaIdx].calcSize(UA_NULL));
 		dst->data = &pData;
-
-		UA_[UA_toIndex(ns0Id)].copy(src->data[0], dst->data[0]);
+		UA_[uaIdx].copy(src->data[0], dst->data[0]);
 	}
 
 	if (src->encodingMask & UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS) {
-		retval |=  UA_Array_copy((const void * const *)(src->arrayDimensions),src->arrayDimensionsLength, UA_INT32_NS0,(void***)&(dst->arrayDimensions));
+		retval |=  UA_Array_copy((const void * const *)(src->arrayDimensions),src->arrayDimensionsLength, UA_toIndex(UA_INT32_NS0),(void***)&(dst->arrayDimensions));
 	}
 	return retval;
 }

+ 31 - 38
tests/check_builtin.c

@@ -1683,8 +1683,8 @@ START_TEST(UA_Variant_copyShallWorkOn1DArrayExample)
 	UA_String **srcArray; UA_Array_new((void***)&srcArray,3,UA_STRING);
 
 	UA_alloc((void**)&dimensions,UA_Int32_calcSize(UA_NULL));
-	UA_String_copycstring("open",srcArray[0]);
-	UA_String_copycstring("62541",srcArray[1]);
+	UA_String_copycstring("__open",srcArray[0]);
+	UA_String_copycstring("_62541",srcArray[1]);
 	UA_String_copycstring("opc ua",srcArray[2]);
 
 	dimensions[0]=3;
@@ -1708,11 +1708,14 @@ START_TEST(UA_Variant_copyShallWorkOn1DArrayExample)
 	ck_assert_int_eq(i1,i2);
 
 	for(i=0;i<3;i++){
-		for(j=0;j<3;j++){
+		for(j=0;j<6;j++){
 			ck_assert_int_eq(((UA_String*)(value->data[i]))->data[j],((UA_String*)(copiedValue->data[i]))->data[j]);
 		}
 		ck_assert_int_eq(((UA_String*)(value->data[i]))->length,((UA_String*)(copiedValue->data[i]))->length);
 	}
+	ck_assert_int_eq(((UA_String*)(copiedValue->data[0]))->data[2],'o');
+	ck_assert_int_eq(((UA_String*)(copiedValue->data[0]))->data[3],'p');
+
 
 	ck_assert_int_eq(value->encodingMask,copiedValue->encodingMask);
 	ck_assert_int_eq(value->arrayDimensionsLength, copiedValue->arrayDimensionsLength);
@@ -1722,41 +1725,36 @@ START_TEST(UA_Variant_copyShallWorkOn1DArrayExample)
 	UA_free(copiedValue);
 }
 END_TEST
-/*
+
 START_TEST(UA_Variant_copyShallWorkOn2DArrayExample)
 {
 	// given
 	UA_Variant *value = UA_NULL;
 	UA_Variant *copiedValue = UA_NULL;
 	UA_Int32 **dimensions;
-	UA_Int32 i,j,i1,i2;
+	UA_Int32 i,i1,i2;
+	UA_Int32 dim1,dim2;
 	UA_Int32 **srcArray;
-	UA_Int32 **dstArray;
-	UA_Array_new((void***)&srcArray,9,UA_INT32);
-
-	//1st line
-	srcArray[0][0] = 0;
-	srcArray[1][0] = 1;
-	srcArray[2][0] = 2;
-	srcArray[0][1] = 3;
-	//2nd line
-	srcArray[0][1] = 4;
-	srcArray[1][1] = 5;
-	srcArray[2][1] = 6;
-	//3rd line
-	srcArray[0][2] = 7;
-	srcArray[1][2] = 8;
-	srcArray[2][2] = 9;
+	UA_Array_new((void***)&srcArray,6,UA_INT32);
+
+	dim1 = 3;
+	dim2 = 2;
+	*srcArray[0] = 0;
+	*srcArray[1] = 1;
+	*srcArray[2] = 2;
+	*srcArray[3] = 3;
+	*srcArray[4] = 4;
+	*srcArray[5] = 5;
 
 	UA_Array_new((void***)&dimensions,2,UA_INT32);
 
-	*(dimensions)[0] = 3;
-	*(dimensions)[1] = 3;
+	*(dimensions)[0] = dim1;
+	*(dimensions)[1] = dim2;
 
 	UA_Variant_new(&value);
 	UA_Variant_new(&copiedValue);
 
-	value->arrayLength = 9;
+	value->arrayLength = 6;
 	value->data = (void**)srcArray;
 	value->arrayDimensionsLength = 2;
 	value->arrayDimensions = dimensions;
@@ -1772,27 +1770,22 @@ START_TEST(UA_Variant_copyShallWorkOn2DArrayExample)
 	i1 = *(value->arrayDimensions)[0],
 	i2 = *(copiedValue->arrayDimensions)[0];
 	ck_assert_int_eq(i1,i2);
+	ck_assert_int_eq(i1, dim1);
 
 
 	//2nd dimension
-	i1 = (value->arrayDimensions)[1][0],
-	i2 = (copiedValue->arrayDimensions)[1][0];
+	i1 = *(value->arrayDimensions)[1];
+	i2 = *(copiedValue->arrayDimensions)[1];
 	ck_assert_int_eq(i1,i2);
+	ck_assert_int_eq(i1, dim2);
 
-	for(i=0;i<9;i++){
+
+	for(i=0;i<6;i++){
 		i1 = *((UA_Int32*)(value->data[i]));
 		i2 = *((UA_Int32*)(copiedValue->data[i]));
 		ck_assert_int_eq(i1,i2);
+		ck_assert_int_eq(i2,i);
 	}
-	dstArray = ((UA_Int32**)(copiedValue->data));
-	for(i=0;i<3;i++){
-		for(j=0;j<3;j++){
-			i1 = srcArray[j][i];
-			i2 = dstArray[j][i];
-			ck_assert_int_eq(i1,i2);
-		}
-	}
-
 
 	ck_assert_int_eq(value->encodingMask,copiedValue->encodingMask);
 	ck_assert_int_eq(value->arrayDimensionsLength, copiedValue->arrayDimensionsLength);
@@ -1803,7 +1796,7 @@ START_TEST(UA_Variant_copyShallWorkOn2DArrayExample)
 
 }
 END_TEST
-*/
+
 Suite *testSuite_builtin(void)
 {
 	Suite *s = suite_create("Built-in Data Types 62541-6 Table 1");
@@ -1923,7 +1916,7 @@ Suite *testSuite_builtin(void)
 
 	tcase_add_test(tc_copy, UA_Variant_copyShallWorkOnSingleValueExample);
 	tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn1DArrayExample);
-	//tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn2DArrayExample);
+	tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn2DArrayExample);
 
 	tcase_add_test(tc_copy, UA_DiagnosticInfo_copyShallWorkOnExample);
 	suite_add_tcase(s,tc_copy);