25 #include "procTypes.h"
26 #include "errorHandle.h"
27 #include "stringManipulate.h"
55 "The bit 1 from the stream is read as 0");
57 "readNextBit returns error code %d", err);
59 "The readNextBit function did not move the bit Pointer of the stream correctly");
67 "The bit 0 from the stream is read as 1");
69 "readNextBit returns error code %d", err);
71 "The readNextBit function did not move the bit Pointer of the stream correctly");
79 "readNextBit returns error code %d", err);
81 "The readNextBit function did not move the bit Pointer of the stream correctly");
93 unsigned int bits_val = 0;
107 err =
readBits(&testStream, 4, &bits_val);
110 "The bits 1101 from the stream are read as %d", bits_val);
112 "readBits returns error code %d", err);
114 "The readBits function did not move the bit Pointer of the stream correctly");
119 err =
readBits(&testStream, 5, &bits_val);
122 "The bits 00110 from the stream are read as %d", bits_val);
124 "readNextBit returns error code %d", err);
126 "The readBits function did not move the bit Pointer of the stream correctly");
128 err =
readBits(&testStream, 5, &bits_val);
145 buf[0] = (char) 0x01;
146 buf[1] = (char) 0x00;
157 test = (buf[0] & 0x80 ) != 0;
160 "The bit 1 was written as 0");
162 "writeNextBit returns error code %d", err);
164 "The writeNextBit function did not move the bit Pointer of the stream correctly");
171 test = (buf[0] & 0x01) != 0;
174 "The bit 0 was written as 1");
176 "writeNextBit returns error code %d", err);
178 "The writeNextBit function did not move the bit Pointer of the stream correctly");
197 buf[0] = (char) 0xA0;
198 buf[1] = (char) 0xE0;
209 test = ((
unsigned int) buf[0]) >> 1;
212 "The number 19 was written as %d", test);
214 "writeNBits returns error code %d", err);
216 "The writeNBits function did not move the bit Pointer of the stream correctly");
223 test = (buf[0] & 0x01 ) != 0;
225 test1 = (buf[1] & 0xF0 ) >> 4;
228 "writeNBits function doesn't write correctly");
230 "writeNBits returns error code %d", err);
232 "The writeNBits function did not move the bit Pointer of the stream correctly");
248 unsigned int bit_val = 0;
254 buf[0] = (char) 0xD4;
255 buf[1] = (char) 0x60;
267 "The 110101 from the stream is read as %d", bit_val);
269 "decodeNBitUnsignedInteger returns error code %d", err);
271 "The decodeNBitUnsignedInteger function did not move the bit Pointer of the stream correctly");
286 buf[0] = (char) 0xD4;
287 buf[1] = (char) 0x60;
299 "The the bit 1 from the stream is read as %d", bit_val);
301 "decodeBoolean returns error code %d", err);
303 "The decodeBoolean function did not move the bit Pointer of the stream correctly");
317 buf[0] = (char) 0xD4;
318 buf[1] = (char) 0x60;
319 buf[2] = (char) 0x48;
331 "The UnsignedInteger 12372 from the stream is read as %d", bit_val);
333 "decodeUnsignedInteger returns error code %d", err);
335 "The decodeUnsignedInteger function did not move the bit Pointer of the stream correctly");
337 "The decodeUnsignedInteger function did not move the byte Pointer of the stream correctly");
354 buf[0] = (char) 0x02;
355 buf[1] = (char) 0x65;
356 buf[2] = (char) 0x54;
357 buf[3] = (char) 0x52;
371 "The String length of 2 is reported as %d from decodeString", bit_val.
length);
373 "The String \"eT\" is decoded wrong by decodeString");
375 "decodeString returns error code %d", err);
377 "The decodeString function did not move the bit Pointer of the stream correctly");
379 "The decodeString function did not move the byte Pointer of the stream correctly");
398 buf[0] = (char) 0x05;
399 buf[1] = (char) 0xF0;
400 buf[2] = (char) 0xCC;
401 buf[3] = (char) 0xAA;
402 buf[4] = (char) 0x55;
403 buf[5] = (char) 0x33;
404 buf[6] = (char) 0x08;
405 buf[7] = (char) 0x6E;
406 buf[8] = (char) 0xCA;
407 buf[9] = (char) 0x59;
408 buf[10] = (char) 0xD8;
409 buf[11] = (char) 0x59;
410 buf[12] = (char) 0xCA;
411 buf[13] = (char) 0x6C;
412 buf[14] = (char) 0xD8;
413 buf[15] = (char) 0x07;
420 for(i=0;i<20;i++) testbuf[i]=buf[i];
429 if(res[i]!=testbuf[i+1])
437 "decodeBinary returns error code %d", err);
439 "The length of the binary content is read as %d (actual : %d)", bytes,5);
441 "The binary content is read wrongly");
443 "The decodeBinary function did not move the bit Pointer of the stream correctly");
445 "The decodeBinary function did not move the byte Pointer of the stream correctly");
456 if(res[i]!=testbuf[i+7])
464 "decodeBinary returns error code %d", err);
466 "The length of the binary content is read as %d (actual : %d)", bytes,8);
468 "The binary content is read wrongly");
470 "The decodeBinary function did not move the bit Pointer of the stream correctly");
472 "The decodeBinary function did not move the byte Pointer of the stream correctly");
482 double expected_res = 500;
484 double actual_res = 0;
490 buf[0] = (char) 0x02;
491 buf[1] = (char) 0x80;
492 buf[2] = (char) 0x92;
504 actual_res = fl_val.mantissa;
505 while(fl_val.exponent)
507 if(fl_val.exponent > 0)
519 "decodeFloat returns error code %d", err);
521 "The float value is read as %f (actual : %f)", actual_res, expected_res);
523 "The decodeBinary function did not move the bit Pointer of the stream correctly");
525 "The decodeBinary function did not move the byte Pointer of the stream correctly");
540 buf[0] = (char) 0x94;
541 buf[1] = (char) 0x60;
542 buf[2] = (char) 0x48;
554 "The IntegerValue -41 from the stream is read as %d", bit_val);
556 "decodeIntegerValue returns error code %d", err);
558 "The decodeIntegerValue function did not move the bit Pointer of the stream correctly");
560 "The decodeIntegerValue function did not move the byte Pointer of the stream correctly");
562 buf[0] = (char) 0x14;
569 "The IntegerValue 40 from the stream is read as %d", bit_val);
571 "decodeIntegerValue returns error code %d", err);
573 "The decodeIntegerValue function did not move the bit Pointer of the stream correctly");
575 "The decodeIntegerValue function did not move the byte Pointer of the stream correctly");
588 dec_val.mantissa = 0;
589 dec_val.exponent = 0;
596 buf[0] = (char) 0x02;
597 buf[1] = (char) 0xB2;
598 buf[2] = (char) 0x12;
610 fail_unless (res.mantissa == dec_val.mantissa && res.exponent == dec_val.exponent,
"The value 5.001 is decoded as %d*10^%d", dec_val.mantissa, dec_val.exponent);
612 "decodeDecimalValue returns error code %d", err);
614 "The decodeIntegerValue function did not move the bit Pointer of the stream correctly");
616 "The decodeIntegerValue function did not move the byte Pointer of the stream correctly");
630 unsigned char test, test2;
635 buf[0] = (char) 0xCE;
636 buf[1] = (char) 0xE0;
648 test2 = (
unsigned char) buf[1] >> 7;
651 "encodeNBitUnsignedInteger returns error code %d", err);
653 "encodeNBitUnsignedInteger does not encode correctly");
655 "The encodeNBitUnsignedInteger function did not move the bit Pointer of the stream correctly");
665 unsigned char bit_val = 0;
670 buf[0] = (char) 0x54;
671 buf[1] = (char) 0x60;
682 bit_val = (
unsigned char) buf[0] >> 7;
685 "encodeBoolean returns error code %d", err);
687 "encodeBoolean does not write correctly");
689 "The encodeBoolean function did not move the bit Pointer of the stream correctly");
693 bit_val = (
unsigned char) buf[0] >> 6;
696 "encodeBoolean returns error code %d", err);
698 "encodeBoolean does not write correctly");
700 "The encodeBoolean function did not move the bit Pointer of the stream correctly");
709 unsigned char test1, test2;
714 buf[0] = (char) 0xD4;
715 buf[1] = (char) 0x00;
716 buf[2] = (char) 0x00;
727 test1 = (
unsigned char) buf[0];
728 test2 = (
unsigned char) buf[1];
731 "encodeUnsignedInteger returns error code %d", err);
733 "The encodeUnsignedInteger function doesn't work correctly");
736 "The encodeUnsignedInteger function did not move the bit Pointer of the stream correctly");
738 "The encodeUnsignedInteger function did not move the byte Pointer of the stream correctly");
740 buf[0] = (char) 0x10;
741 buf[1] = (char) 0x00;
742 buf[2] = (char) 0x00;
749 test1 = (
unsigned char) buf[0];
750 test2 = (
unsigned char) buf[1];
753 "encodeUnsignedInteger returns error code %d", err);
755 "The encodeUnsignedInteger function doesn't work correctly");
757 "The encodeUnsignedInteger function did not move the bit Pointer of the stream correctly");
759 "The encodeUnsignedInteger function did not move the byte Pointer of the stream correctly");
770 unsigned char str_len;
775 buf[0] = (char) 0x02;
776 buf[1] = (char) 0x65;
777 buf[2] = (char) 0x64;
778 buf[3] = (char) 0x62;
793 "encodeString returns error code %d", err);
795 "The String length is not encoded correctly");
797 "encodeString doesn't encode correctly");
799 "The encodeString function did not move the bit Pointer of the stream correctly");
801 "The encodeString function did not move the byte Pointer of the stream correctly");
815 bin_data[0] = (char) 0x22;
816 bin_data[1] = (char) 0x65;
817 bin_data[2] = (char) 0xD4;
818 bin_data[3] = (char) 0x5A;
819 bin_data[4] = (char) 0xD7;
832 "encodeBinary returns error code %d", err);
834 "The encodeBinary function did not move the bit Pointer of the stream correctly");
836 "The encodeBinary function did not move the byte Pointer of the stream correctly");
839 fail_unless(testStream.
buffer.
buf[1] == (
signed char) 0x22,
"Incorrect encoding during encodeBinary 2");
840 fail_unless(testStream.
buffer.
buf[2] == (
signed char) 0x65,
"Incorrect encoding during encodeBinary 3");
841 fail_unless(testStream.
buffer.
buf[3] == (
signed char) 0xD4,
"Incorrect encoding during encodeBinary 4");
842 fail_unless(testStream.
buffer.
buf[4] == (
signed char) 0x5A,
"Incorrect encoding during encodeBinary 5");
843 fail_unless(testStream.
buffer.
buf[5] == (
signed char) 0xD7,
"Incorrect encoding during encodeBinary 6");
856 test_val.mantissa = 5;
857 test_val.exponent = 2;
873 "encodeFloatValue returns error code %d", err);
876 "The encodeFloatValue function did not move the bit Pointer of the stream correctly");
878 "The encodeFloatValue function did not move the byte Pointer of the stream correctly");
883 test_dec.mantissa = 0;
884 test_dec.exponent = 0;
887 fail_unless(test_val.exponent == test_dec.exponent && test_val.mantissa == test_dec.mantissa
888 ,
"Incorrect encoding of float value");
914 "encodeIntegerValue returns error code %d", err);
916 "The encodeIntegerValue function did not move the bit Pointer of the stream correctly");
918 "The encodeIntegerValue function did not move the byte Pointer of the stream correctly");
926 "The encodeIntegerValue encodes correctly");
938 dec_val.mantissa = 0;
939 dec_val.exponent = 0;
958 "encodeDecimalValue returns error code %d", err);
961 "The encodeDecimalValue function did not move the bit Pointer of the stream correctly");
963 "The encodeDecimalValue function did not move the byte Pointer of the stream correctly");
970 fail_unless (res.mantissa == dec_val.mantissa && res.exponent == dec_val.exponent,
"The value 5.001 is decoded as %d*10^%d", dec_val.mantissa, dec_val.exponent);
1100 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;