re organize tests for floating point mostly into one place; CAF floating point tests are passing
diff --git a/test/half_precision_test.c b/test/float_tests.c
similarity index 86%
rename from test/half_precision_test.c
rename to test/float_tests.c
index 936d70f..1bff43c 100644
--- a/test/half_precision_test.c
+++ b/test/float_tests.c
@@ -1,5 +1,5 @@
/*==============================================================================
- half_precision_test.c -- tests for converstion to/from half-precision
+ float_tests.c -- tests for float and conversion to/from half-precision
Copyright 2018 Laurence Lundblade
@@ -28,11 +28,110 @@
// Created by Laurence Lundblade on 9/19/18.
-#include "half_precision_test.h"
+#include "float_tests.h"
#include "qcbor.h"
#include "half_to_double_from_rfc7049.h"
#include <math.h> // For INFINITY and NAN and isnan()
+
+
+
+static uint8_t pExpectedEncodedFloat[] = {
+ 0x98, 0x1e, 0xfa, 0x00, 0x00, 0x00, 0x00, 0xfa,
+ 0x3f, 0x80, 0x00, 0x00, 0xfa, 0x3f, 0x8c, 0xcc,
+ 0xcd, 0xfa, 0x3f, 0xc0, 0x00, 0x00, 0xfa, 0x47,
+ 0x7f, 0xe0, 0x00, 0xfa, 0x47, 0xc3, 0x50, 0x00,
+ 0xfa, 0x7f, 0x7f, 0xff, 0xff, 0xfa, 0x7f, 0x80,
+ 0x00, 0x00, 0xfa, 0x33, 0x80, 0x00, 0x00, 0xfa,
+ 0x38, 0x80, 0x00, 0x00, 0xfa, 0xc0, 0x80, 0x00,
+ 0x00, 0xfa, 0xc0, 0x83, 0x33, 0x33, 0xfa, 0x7f,
+ 0xc0, 0x00, 0x00, 0xfa, 0x7f, 0x80, 0x00, 0x00,
+ 0xfa, 0xff, 0x80, 0x00, 0x00, 0xfb, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x3f,
+ 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb,
+ 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a,
+ 0xfb, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xfb, 0x40, 0xef, 0xfc, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xfb, 0x40, 0xf8, 0x6a, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xfb, 0x47, 0xef, 0xff, 0xff,
+ 0xe0, 0x00, 0x00, 0x00, 0xfb, 0x7e, 0x37, 0xe4,
+ 0x3c, 0x88, 0x00, 0x75, 0x9c, 0xfb, 0x3e, 0x70,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x3f,
+ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb,
+ 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66,
+ 0x66, 0xfb, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xfb, 0x7f, 0xf0, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xfb, 0xff, 0xf0, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
+
+
+int FloatValuesTest1()
+{
+ QCBOREncodeContext ECtx;
+ int nReturn = 0;
+
+ UsefulBuf_MakeStackUB(EncodedStorage, 1000);
+
+ QCBOREncode_Init(&ECtx, EncodedStorage);
+ QCBOREncode_OpenArray(&ECtx);
+
+ // These are all samples published
+ // in RFC 7049.
+ QCBOREncode_AddFloat(&ECtx, 0.0);
+ QCBOREncode_AddFloat(&ECtx, 1.0);
+ QCBOREncode_AddFloat(&ECtx, 1.1); // appx
+ QCBOREncode_AddFloat(&ECtx, 1.5);
+ QCBOREncode_AddFloat(&ECtx, 65504.0);
+ QCBOREncode_AddFloat(&ECtx, 100000.0);
+ QCBOREncode_AddFloat(&ECtx, 3.4028234663852886e+38);
+ QCBOREncode_AddFloat(&ECtx, 1.0e+300); // Infinity?
+ QCBOREncode_AddFloat(&ECtx, 5.960464477539063e-8);
+ QCBOREncode_AddFloat(&ECtx, 0.00006103515625);
+ QCBOREncode_AddFloat(&ECtx, -4.0);
+ QCBOREncode_AddFloat(&ECtx, -4.1); // appx
+
+ QCBOREncode_AddFloat(&ECtx, NAN);
+ QCBOREncode_AddFloat(&ECtx, INFINITY);
+ QCBOREncode_AddFloat(&ECtx, -INFINITY);
+
+
+ QCBOREncode_AddDouble(&ECtx, 0.0);
+ QCBOREncode_AddDouble(&ECtx, 1.0);
+ QCBOREncode_AddDouble(&ECtx, 1.1); // appx
+ QCBOREncode_AddDouble(&ECtx, 1.5);
+ QCBOREncode_AddDouble(&ECtx, 65504.0);
+ QCBOREncode_AddDouble(&ECtx, 100000.0);
+ QCBOREncode_AddDouble(&ECtx, 3.4028234663852886e+38);
+ QCBOREncode_AddDouble(&ECtx, 1.0e+300); // Infinity?
+ QCBOREncode_AddDouble(&ECtx, 5.960464477539063e-8);
+ QCBOREncode_AddDouble(&ECtx, 0.00006103515625);
+ QCBOREncode_AddDouble(&ECtx, -4.0);
+ QCBOREncode_AddDouble(&ECtx, -4.1); // appx
+
+ QCBOREncode_AddDouble(&ECtx, NAN);
+ QCBOREncode_AddDouble(&ECtx, INFINITY);
+ QCBOREncode_AddDouble(&ECtx, -INFINITY);
+
+ QCBOREncode_CloseArray(&ECtx);
+
+ UsefulBufC Encoded;
+ if(QCBOREncode_Finish2(&ECtx, &Encoded)) {
+ nReturn = -1;
+ }
+
+ if(UsefulBuf_Compare(Encoded, UsefulBuf_FromByteArrayLiteral(pExpectedEncodedFloat))) {
+ nReturn = -2;
+ }
+
+ //printencoded(pEncoded, nEncodedLen);
+
+ return(nReturn);
+}
+
+
+
+
static const uint8_t ExpectedHalf[] = {
0xB1,
0x64,
diff --git a/test/half_precision_test.h b/test/float_tests.h
similarity index 89%
rename from test/half_precision_test.h
rename to test/float_tests.h
index 1367db5..5bb638b 100644
--- a/test/half_precision_test.h
+++ b/test/float_tests.h
@@ -1,5 +1,5 @@
/*==============================================================================
- half_precision_test.h -- tests for converstion to/from half-precision
+ float_tests.h -- tests for float and conversion to/from half-precision
Copyright 2018 Laurence Lundblade
@@ -28,8 +28,10 @@
// Created by Laurence Lundblade on 9/19/18.
-#ifndef half_precision_test_h
-#define half_precision_test_h
+#ifndef float_tests_h
+#define float_tests_h
+
+int FloatValuesTest1(void);
int half_precision_encode_basic(void);
@@ -42,4 +44,4 @@
int half_precision_to_float_vs_rfc_test(void);
-#endif /* half_precision_test_h */
+#endif /* float_tests_h */
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index 4a79bbd..39e3fc5 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -686,102 +686,8 @@
return(nReturn);
}
-#if 0
-static uint8_t pExpectedEncodedFloat[] = {
- 0x98, 0x1e, 0xfa, 0x00, 0x00, 0x00, 0x00, 0xfa,
- 0x3f, 0x80, 0x00, 0x00, 0xfa, 0x3f, 0x8c, 0xcc,
- 0xcd, 0xfa, 0x3f, 0xc0, 0x00, 0x00, 0xfa, 0x47,
- 0x7f, 0xe0, 0x00, 0xfa, 0x47, 0xc3, 0x50, 0x00,
- 0xfa, 0x7f, 0x7f, 0xff, 0xff, 0xfa, 0x7f, 0x80,
- 0x00, 0x00, 0xfa, 0x33, 0x80, 0x00, 0x00, 0xfa,
- 0x38, 0x80, 0x00, 0x00, 0xfa, 0xc0, 0x80, 0x00,
- 0x00, 0xfa, 0xc0, 0x83, 0x33, 0x33, 0xfa, 0x7f,
- 0xc0, 0x00, 0x00, 0xfa, 0x7f, 0x80, 0x00, 0x00,
- 0xfa, 0xff, 0x80, 0x00, 0x00, 0xfb, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x3f,
- 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb,
- 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a,
- 0xfb, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xfb, 0x40, 0xef, 0xfc, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfb, 0x40, 0xf8, 0x6a, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xfb, 0x47, 0xef, 0xff, 0xff,
- 0xe0, 0x00, 0x00, 0x00, 0xfb, 0x7e, 0x37, 0xe4,
- 0x3c, 0x88, 0x00, 0x75, 0x9c, 0xfb, 0x3e, 0x70,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x3f,
- 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb,
- 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66,
- 0x66, 0xfb, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xfb, 0x7f, 0xf0, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xfb, 0xff, 0xf0, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00};
-
-
-int FloatValuesTest1()
-{
- QCBOREncodeContext ECtx;
- int nReturn = 0;
-
- uint8_t pEncoded[1000];
- size_t nEncodedLen = sizeof(pEncoded);
-
- QCBOREncode_Init(&ECtx, pEncoded, nEncodedLen);
- QCBOREncode_OpenArray(&ECtx);
-
- // These are all samples published
- // in RFC 7049.
- QCBOREncode_AddFloat(&ECtx, 0.0);
- QCBOREncode_AddFloat(&ECtx, 1.0);
- QCBOREncode_AddFloat(&ECtx, 1.1); // appx
- QCBOREncode_AddFloat(&ECtx, 1.5);
- QCBOREncode_AddFloat(&ECtx, 65504.0);
- QCBOREncode_AddFloat(&ECtx, 100000.0);
- QCBOREncode_AddFloat(&ECtx, 3.4028234663852886e+38);
- QCBOREncode_AddFloat(&ECtx, 1.0e+300); // Infinity?
- QCBOREncode_AddFloat(&ECtx, 5.960464477539063e-8);
- QCBOREncode_AddFloat(&ECtx, 0.00006103515625);
- QCBOREncode_AddFloat(&ECtx, -4.0);
- QCBOREncode_AddFloat(&ECtx, -4.1); // appx
-
- QCBOREncode_AddFloat(&ECtx, NAN);
- QCBOREncode_AddFloat(&ECtx, INFINITY);
- QCBOREncode_AddFloat(&ECtx, -INFINITY);
-
-
- QCBOREncode_AddDouble(&ECtx, 0.0);
- QCBOREncode_AddDouble(&ECtx, 1.0);
- QCBOREncode_AddDouble(&ECtx, 1.1); // appx
- QCBOREncode_AddDouble(&ECtx, 1.5);
- QCBOREncode_AddDouble(&ECtx, 65504.0);
- QCBOREncode_AddDouble(&ECtx, 100000.0);
- QCBOREncode_AddDouble(&ECtx, 3.4028234663852886e+38);
- QCBOREncode_AddDouble(&ECtx, 1.0e+300); // Infinity?
- QCBOREncode_AddDouble(&ECtx, 5.960464477539063e-8);
- QCBOREncode_AddDouble(&ECtx, 0.00006103515625);
- QCBOREncode_AddDouble(&ECtx, -4.0);
- QCBOREncode_AddDouble(&ECtx, -4.1); // appx
-
- QCBOREncode_AddDouble(&ECtx, NAN);
- QCBOREncode_AddDouble(&ECtx, INFINITY);
- QCBOREncode_AddDouble(&ECtx, -INFINITY);
-
- QCBOREncode_CloseArray(&ECtx);
- if(QCBOREncode_Finish(&ECtx, &nEncodedLen)) {
- nReturn = -1;
- }
-
- if(nEncodedLen != sizeof(pExpectedEncodedFloat) || bcmp(pEncoded, pExpectedEncodedFloat, nEncodedLen))
- nReturn = -1;
-
- //printencoded(pEncoded, nEncodedLen);
-
- return(nReturn);
-}
-
-#endif
-
static uint8_t pExpectedEncodedDates[] = {
0x83, 0xc0, 0x74, 0x32, 0x30, 0x31, 0x33, 0x2d, 0x30, 0x33, 0x2d, 0x32, 0x31, 0x54,
0x32, 0x30, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x30,
diff --git a/test/run_tests.c b/test/run_tests.c
index ae184d8..38341a8 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -33,7 +33,7 @@
#include "UsefulBuf.h"
#include <stdbool.h>
-#include "half_precision_test.h"
+#include "float_tests.h"
#include "basic_test.h"
#include "bstrwrap_tests.h"
#include "mempool_test.h"
@@ -115,6 +115,7 @@
test_entry s_tests[] = {
+ TEST_ENTRY(FloatValuesTest1),
TEST_ENTRY(RTICResultsTest),
TEST_ENTRY(MapEncodeTest),
TEST_ENTRY(ArrayNestingTest1),