You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kp...@apache.org on 2020/07/09 20:06:13 UTC
[qpid-proton] branch array-of-lists-first-list-empty updated:
PROTON-2244: Removed array codec tests from Python to C/C++ tests as
requested
This is an automated email from the ASF dual-hosted git repository.
kpvdr pushed a commit to branch array-of-lists-first-list-empty
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/array-of-lists-first-list-empty by this push:
new 00d9446 PROTON-2244: Removed array codec tests from Python to C/C++ tests as requested
00d9446 is described below
commit 00d9446248b14ef729162ef52b65a8dd438820cf
Author: Kim van der Riet <kp...@apache.org>
AuthorDate: Thu Jul 9 16:05:56 2020 -0400
PROTON-2244: Removed array codec tests from Python to C/C++ tests as requested
---
c/tests/data_test.cpp | 145 ++++++++++++++++++++++
python/tests/proton_tests/codec.py | 246 +------------------------------------
2 files changed, 146 insertions(+), 245 deletions(-)
diff --git a/c/tests/data_test.cpp b/c/tests/data_test.cpp
index a15c1b4..6a45958 100644
--- a/c/tests/data_test.cpp
+++ b/c/tests/data_test.cpp
@@ -25,6 +25,13 @@
#include <proton/codec.h>
#include <proton/error.h>
+//#include <proton/types.hpp>
+
+#include <cstdarg> // va_start(), va_end()
+#include <ctime> // time()
+#include <unistd.h> // ssize_t
+
+#include <iostream> // DEBUG
using namespace pn_test;
@@ -105,3 +112,141 @@ TEST_CASE("data_multiple") {
pn_data_fill(data, "{S[iii]SI}", "foo", 1, 987, 3, "bar", 965);
CHECK("{\"foo\"=[1, 987, 3], \"bar\"=965}" == inspect(data));
}
+
+#define BUFSIZE 1024
+
+static void check_array(const char *fmt, ...) {
+ char buf[BUFSIZE];
+ auto_free<pn_data_t, pn_data_free> src(pn_data(1));
+ auto_free<pn_data_t, pn_data_free> data(pn_data(1));
+ pn_data_clear(src);
+ pn_data_clear(data);
+
+ // Create src array
+ va_list ap;
+ va_start(ap, fmt);
+ pn_data_vfill(src, fmt, ap);
+ va_end(ap);
+
+ // Encode src array to buf
+ ssize_t enc_size = pn_data_encode(src, buf, BUFSIZE - 1);
+ if (enc_size < 0) {
+ std::cout << "ENC ERR: " << pn_code(enc_size) << std::endl;
+ return;
+ }
+
+ // Decode buf to data
+ ssize_t dec_size = pn_data_decode(data, buf, BUFSIZE - 1);
+ pn_error_t *dec_err = pn_data_error(data);
+ if (dec_size < 0) {
+ std::cout << "DEC ERR: " << pn_code(dec_size) << std::endl;
+ return;
+ }
+
+ // Checks
+ CHECK(enc_size == dec_size);
+ CHECK(inspect(src) == inspect(data));
+}
+
+TEST_CASE("array_null") {
+ check_array("@T[]", PN_NULL);
+ check_array("@T[nnn]", PN_NULL);
+}
+
+TEST_CASE("array_bool") {
+ check_array("@T[]", PN_BOOL);
+ check_array("@T[oooo]", PN_BOOL, true, false, false, true);
+}
+
+TEST_CASE("array_ubyte") {
+ check_array("@T[]", PN_UBYTE);
+ check_array("@T[BBBBB]", PN_UBYTE, uint8_t(0), uint8_t(1), uint8_t(0x7f), uint8_t(0x80), uint8_t(0xff));
+}
+
+TEST_CASE("array_byte") {
+ check_array("@T[]", PN_BYTE);
+ check_array("@T[bbbbb]", PN_BYTE, int8_t(-0x80), int8_t(-1), int8_t(0), int8_t(1), int8_t(0x7f));
+}
+
+TEST_CASE("array_ushort") {
+ check_array("@T[]", PN_USHORT);
+ check_array("@T[HHHHH]", PN_USHORT, uint16_t(0), uint16_t(1), uint16_t(0x7fff), uint16_t(0x8000), uint16_t(0xffff));
+}
+
+TEST_CASE("array_short") {
+ check_array("@T[]", PN_SHORT);
+ check_array("@T[hhhhh]", PN_SHORT, int16_t(-0x8000), int16_t(-1), int16_t(0), int16_t(1), int16_t(0x7fff));
+}
+
+TEST_CASE("array_uint") {
+ check_array("@T[]", PN_UINT);
+ check_array("@T[IIIII]", PN_UINT, uint32_t(0), uint32_t(1), uint32_t(0x7fffffff), uint32_t(0x80000000), uint32_t(0xffffffff));
+}
+
+TEST_CASE("array_int") {
+ check_array("@T[]", PN_INT);
+ check_array("@T[iiiii]", PN_INT, int32_t(-0x80000000), int32_t(-1), int32_t(0), int32_t(1), int32_t(0x7fffffff));
+}
+
+TEST_CASE("array_ulong") {
+ check_array("@T[]", PN_ULONG);
+ check_array("@T[LLLLL]", PN_ULONG, uint64_t(0), uint64_t(1), uint64_t(0x7fffffffffffffff), uint64_t(0x8000000000000000), uint64_t(0xffffffffffffffff));
+}
+
+TEST_CASE("array_long") {
+ check_array("@T[]", PN_LONG);
+ check_array("@T[lllll]", PN_LONG, int64_t(-0x8000000000000000), int64_t(-1), int64_t(0), int64_t(1), int64_t(0x8000000000000000));
+}
+
+TEST_CASE("array_timestamp") {
+ check_array("@T[]", PN_TIMESTAMP);
+ check_array("@T[ttt]", PN_TIMESTAMP, int64_t(0), int64_t(std::time(nullptr)*1000), int64_t(0x123456789abcdef));
+}
+
+TEST_CASE("array_float") {
+ check_array("@T[]", PN_FLOAT);
+ check_array("@T[fffff]", PN_FLOAT, float(0.0), float(3.14), std::nanf, std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity());
+}
+
+TEST_CASE("array_double") {
+ check_array("@T[]", PN_DOUBLE);
+ check_array("@T[ddddd]", PN_DOUBLE, double(0.0), double(3.1416), std::nan, std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity());
+}
+
+TEST_CASE("array_binary") {
+ check_array("@T[]", PN_BINARY);
+ check_array("@T[zzzzz]", PN_BINARY, 0, "", 2, "\x00\x00", 4, "\x00\x01\xfe\xff", 8, "abcdefgh", 16, "1234567890123456");
+}
+
+TEST_CASE("array_string") {
+ check_array("@T[]", PN_STRING);
+ // TODO: PROTON-2248: using S and s reversed
+ check_array("@T[SSSSS]", PN_STRING, "", "hello", "bye", "abcdefg", "the quick brown fox jumped over the lazy dog 0123456789");
+}
+
+TEST_CASE("array_symbol") {
+ check_array("@T[]", PN_SYMBOL);
+ // TODO: PROTON-2248: using S and s reversed
+ check_array("@T[sssss]", PN_SYMBOL, "", "hello", "bye", "abcdefg", "the quick brown fox jumped over the lazy dog 0123456789");
+}
+
+TEST_CASE("array_array") {
+ check_array("@T[]", PN_ARRAY);
+ // TODO: PROTON-2248: using S and s reversed
+ check_array("@T[@T[]@T[ooo]@T[ii]@T[nnnn]@T[sss]]", PN_ARRAY, PN_UBYTE, PN_BOOL, false, false, true, PN_INT, -100, 100, PN_NULL, PN_SYMBOL, "aaa", "bbb", "ccc");
+}
+
+TEST_CASE("array_list") {
+ check_array("@T[]", PN_LIST);
+ // TODO: PROTON-2248: using S and s reversed
+ check_array("@T[[][oo][][iii][Sosid]]", PN_LIST, true, false, 1, 2, 3, "hello", false, "world", 43210, 2.565);
+}
+
+TEST_CASE("array_map") {
+ check_array("@T[]", PN_MAP);
+ // TODO: PROTON-2248: using S and s reversed
+ check_array("@T[{}{sS}{}{IhIoIf}{iSiSiSiS}]", PN_MAP, "key", "value", 123, -123, 255, false, 0, 0.25, 0, "zero", 1, "one", 2, "two", 3, "three");
+}
+
+
+
diff --git a/python/tests/proton_tests/codec.py b/python/tests/proton_tests/codec.py
index ee644ef..bc66463 100644
--- a/python/tests/proton_tests/codec.py
+++ b/python/tests/proton_tests/codec.py
@@ -19,10 +19,8 @@
from __future__ import absolute_import
-import struct
import sys
-import time
-from uuid import UUID, uuid4
+from uuid import uuid4
from proton import *
from proton._compat import raise_
@@ -224,248 +222,6 @@ class DataTest(Test):
def testDescribedEmptyArray(self):
self._testArray("long", 0, "null")
- def _testPyArray(self, a1):
- d1 = Data()
- d1.put_py_array(a1)
- d2 = Data()
- d2.decode(d1.encode())
- a2 = d2.get_py_array()
- assert a1 == a2, 'a1=%s a2=%s' % (a1, a2)
-
- def testEmptyNullPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.NULL))
-
- def testNullPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.NULL, None, None, None))
-
- def testEmptyBooleanPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.BOOL))
-
- def testBooleanPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.BOOL, True, False, False, True))
-
- def testEmptyBytePyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.BYTE))
-
- def testBytePyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.BYTE,
- byte(-0x80),
- byte(-1),
- byte(0),
- byte(1),
- byte(0x7f)))
-
- def testEmptyUbytePyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.UBYTE))
-
- def testUbytePyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.UBYTE,
- ubyte(0),
- ubyte(1),
- ubyte(0x7f),
- ubyte(0x80),
- ubyte(0xff)))
-
- def testEmptyShortPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.SHORT))
-
- def testShortPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.SHORT,
- short(-0x8000),
- short(-1),
- short(0),
- short(1),
- short(0x7fff)))
-
- def testEmptyUshortPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.USHORT))
-
- def testUshortPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.USHORT,
- ushort(0),
- ushort(1),
- ushort(0x7fff),
- ushort(0x8000),
- ushort(0xffff)))
-
- def testEmptyIntPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.INT))
-
- def testIntPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.INT,
- int32(-0x80000000),
- int32(-1),
- int32(0),
- int32(1),
- int32(0x7fffffff)))
-
- def testEmptyUintPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.UINT))
-
- def testUintPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.UINT,
- uint(0),
- uint(1),
- uint(0x7fffffff),
- uint(0x80000000),
- uint(0xffffffff)))
-
- def testEmptyLongPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.LONG))
-
- def testLongPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.LONG,
- long(-0x8000000000000000),
- long(-1),
- long(0),
- long(1),
- long(0x7fffffffffffffff)))
-
- def testEmptyUlongPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.ULONG))
-
- def testUlongPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.ULONG,
- ulong(0),
- ulong(1),
- ulong(0x7fffffffffffffff),
- ulong(0x8000000000000000),
- ulong(0xffffffffffffffff)))
-
- def testEmptyFloatPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.FLOAT))
-
- def testFloatPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.FLOAT,
- float32(0.0),
- float32(struct.unpack('!f', b'\x40\x49\x0f\xf9')[0]), # 3.14
- float32('-inf'),
- float32('inf')))
-
- def testEmptyDoublePyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DOUBLE))
-
- def testDoublePyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DOUBLE,
- 0.0,
- struct.unpack('!d', b'\x40\x09\x21\xff\x2e\x48\xe8\xa7')[0], # 3.1416
- float('-inf'),
- float('inf')))
-
- def testEmptyCharPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.CHAR))
-
- def testCharPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.CHAR,
- char('a'),
- char('Z'),
- char(chr(0)),
- char(chr(0x7f))))
-
- def testEmptyDecimal32PyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DECIMAL32))
-
- def testDecimal32PyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DECIMAL32,
- decimal32(0),
- decimal32(0x01020304),
- decimal32(0xfcfdfeff)))
-
- def testEmptyDecimal64PyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DECIMAL64))
-
- def testDecimal64PyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DECIMAL64,
- decimal64(0),
- decimal64(0x0102030405060708),
- decimal64(0xf8f9fafbfcfdfeff)))
-
- def testEmptyDecimal128PyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DECIMAL128))
-
- def testDecimal128PyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.DECIMAL128,
- decimal128(b'\x00'*16),
- decimal128(b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x00'),
- decimal128(b'\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')))
-
- def testEmptyTimestampPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.TIMESTAMP))
-
- def testTimestampPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.TIMESTAMP,
- timestamp(0),
- timestamp(time.time()*1000)))
-
- def testEmptyBinaryPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.BINARY))
-
- def testBinaryPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.BINARY,
- b'',
- b'\x00\x01\x02test\xfe\xff',
- b'Hello world',
- b'"hello"'))
-
- def testEmptyStringPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.STRING))
-
- def testStringPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.STRING,
- '',
- 'Hello world',
- '"Hello, world"',
- 'goodbye'))
-
- def testEmptySymbolPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.SYMBOL))
-
- def testSymbolPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.SYMBOL,
- symbol(),
- symbol('12345'),
- symbol('myDomain.123'),
- symbol('domain.0123456789.' * 10)))
-
- def testEmptyUUIDPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.UUID))
-
- def testUUIDPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.UUID,
- UUID(int=0x0),
- UUID('00010203-0405-0607-0809-0a0b0c0d0e0f'),
- uuid4()))
-
- def testEmptyListPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.LIST))
-
- def testListPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.LIST,
- [],
- [1, 2, 3],
- [],
- ['aaa', 'bbb', 'ccc'],
- [1, 3.14, ubyte(0xdc), symbol('12345'), uuid4(), 'hello']))
-
- def testEmptyMapPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.MAP))
-
- def testMapPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.MAP,
- {},
- {'one':1, 'two':2, 'three':3},
- {},
- {1:'one', 2:'two', 3:'three'}))
-
- def testEmptyArrayPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.ARRAY))
-
- def testArrayPyArray(self):
- self._testPyArray(Array(UNDESCRIBED, Data.ARRAY,
- Array(UNDESCRIBED, Data.NULL),
- Array(UNDESCRIBED, Data.BOOL, True, False),
- Array(UNDESCRIBED, Data.STRING, 'aaa', 'bbb')))
-
def testPropertyDict(self):
a = PropertyDict(one=1, two=2, three=3)
b = PropertyDict({'one': 1, 'two': 2, 'three': 3})
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org