You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/12/28 19:08:48 UTC
incubator-mynewt-core git commit: cborattr; start writing unittests.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop f4504a5ba -> c784c5dad
cborattr; start writing unittests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c784c5da
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c784c5da
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c784c5da
Branch: refs/heads/develop
Commit: c784c5dad44b36bbd4f580b3b9905158e9bc06c7
Parents: f4504a5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Dec 28 11:08:25 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Dec 28 11:08:25 2016 -0800
----------------------------------------------------------------------
encoding/cborattr/test/pkg.yml | 31 ++++++++
encoding/cborattr/test/src/test_cborattr.c | 41 ++++++++++
encoding/cborattr/test/src/test_cborattr.h | 50 ++++++++++++
.../cborattr/test/src/test_cborattr_utils.c | 35 +++++++++
.../test/src/testcases/cborattr_decode1.c | 83 ++++++++++++++++++++
.../test/src/testcases/cborattr_decode2.c | 47 +++++++++++
6 files changed, 287 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c784c5da/encoding/cborattr/test/pkg.yml
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/pkg.yml b/encoding/cborattr/test/pkg.yml
new file mode 100644
index 0000000..381cb47
--- /dev/null
+++ b/encoding/cborattr/test/pkg.yml
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+pkg.name: encoding/cborattr/test
+pkg.type: unittest
+pkg.description: "CBOR attr unit tests."
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - encoding/tinycbor
+ - encoding/cborattr
+ - test/testutil
+
+pkg.deps.SELFTEST:
+ - sys/console/stub
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c784c5da/encoding/cborattr/test/src/test_cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/test_cborattr.c b/encoding/cborattr/test/src/test_cborattr.c
new file mode 100644
index 0000000..410b87e
--- /dev/null
+++ b/encoding/cborattr/test/src/test_cborattr.c
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+#include "test_cborattr.h"
+
+TEST_SUITE(test_cborattr_suite)
+{
+ test_cborattr_decode1();
+ test_cborattr_decode2();
+}
+
+#if MYNEWT_VAL(SELFTEST)
+int
+main(int argc, char **argv)
+{
+ ts_config.ts_print_results = 1;
+ tu_init();
+
+ test_cborattr_suite();
+
+ return tu_any_failed;
+}
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c784c5da/encoding/cborattr/test/src/test_cborattr.h
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/test_cborattr.h b/encoding/cborattr/test/src/test_cborattr.h
new file mode 100644
index 0000000..c2c0ba3
--- /dev/null
+++ b/encoding/cborattr/test/src/test_cborattr.h
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef TEST_CBORATTR_H
+#define TEST_CBORATTR_H
+
+#include <assert.h>
+#include <string.h>
+#include "testutil/testutil.h"
+#include "test_cborattr.h"
+#include "tinycbor/cbor.h"
+#include "cborattr/cborattr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Returns test data.
+ */
+const uint8_t *test_str1(int *len);
+
+/*
+ * Testcases
+ */
+TEST_CASE_DECL(test_cborattr_decode1);
+TEST_CASE_DECL(test_cborattr_decode2);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TEST_CBORATTR_H */
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c784c5da/encoding/cborattr/test/src/test_cborattr_utils.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/test_cborattr_utils.c b/encoding/cborattr/test/src/test_cborattr_utils.c
new file mode 100644
index 0000000..0a43766
--- /dev/null
+++ b/encoding/cborattr/test/src/test_cborattr_utils.c
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "test_cborattr.h"
+/*
+ * {"a": "A", "b": "B", "c": "C", "d": "D", "e": "E"}
+ */
+static const uint8_t test_data1[] = {
+ 0xa5, 0x61, 0x61, 0x61, 0x41, 0x61, 0x62, 0x61,
+ 0x42, 0x61, 0x63, 0x61, 0x43, 0x61, 0x64, 0x61,
+ 0x44, 0x61, 0x65, 0x61, 0x45
+};
+
+const uint8_t *
+test_str1(int *len)
+{
+ *len = sizeof(test_data1);
+ return (test_data1);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c784c5da/encoding/cborattr/test/src/testcases/cborattr_decode1.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/testcases/cborattr_decode1.c b/encoding/cborattr/test/src/testcases/cborattr_decode1.c
new file mode 100644
index 0000000..1b6cddf
--- /dev/null
+++ b/encoding/cborattr/test/src/testcases/cborattr_decode1.c
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "test_cborattr.h"
+
+/*
+ * Simple decoding.
+ */
+TEST_CASE(test_cborattr_decode1)
+{
+ const uint8_t *data;
+ int len;
+ int rc;
+ char test_str_a[4] = { '\0' };
+ char test_str_b[4] = { '\0' };
+ char test_str_c[4] = { '\0' };
+ char test_str_d[4] = { '\0' };
+ char test_str_e[4] = { '\0' };
+ struct cbor_attr_t test_attrs[] = {
+ [0] = {
+ .attribute = "a",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_a,
+ .len = sizeof(test_str_a),
+ .nodefault = true
+ },
+ [1] = {
+ .attribute = "b",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_b,
+ .len = sizeof(test_str_b),
+ .nodefault = true
+ },
+ [2] = {
+ .attribute = "c",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_c,
+ .len = sizeof(test_str_c),
+ .nodefault = true
+ },
+ [3] = {
+ .attribute = "d",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_d,
+ .len = sizeof(test_str_d),
+ .nodefault = true,
+ },
+ [4] = {
+ .attribute = "e",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_e,
+ .len = sizeof(test_str_e),
+ .nodefault = true,
+ },
+ [5] = {
+ .attribute = NULL
+ }
+ };
+
+ data = test_str1(&len);
+ rc = cbor_read_flat_attrs(data, len, test_attrs);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(!strcmp(test_str_a, "A"));
+ TEST_ASSERT(!strcmp(test_str_b, "B"));
+ TEST_ASSERT(!strcmp(test_str_c, "C"));
+ TEST_ASSERT(!strcmp(test_str_d, "D"));
+ TEST_ASSERT(!strcmp(test_str_e, "E"));
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c784c5da/encoding/cborattr/test/src/testcases/cborattr_decode2.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/testcases/cborattr_decode2.c b/encoding/cborattr/test/src/testcases/cborattr_decode2.c
new file mode 100644
index 0000000..5504158
--- /dev/null
+++ b/encoding/cborattr/test/src/testcases/cborattr_decode2.c
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "test_cborattr.h"
+
+/*
+ * Simple decoding. Only have key for one of the key/value pairs.
+ */
+TEST_CASE(test_cborattr_decode2)
+{
+ const uint8_t *data;
+ int len;
+ int rc;
+ char test_str_b[4] = { '\0' };
+ struct cbor_attr_t test_attrs[] = {
+ [0] = {
+ .attribute = "b",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_b,
+ .len = sizeof(test_str_b),
+ .nodefault = true
+ },
+ [1] = {
+ .attribute = NULL
+ }
+ };
+
+ data = test_str1(&len);
+ rc = cbor_read_flat_attrs(data, len, test_attrs);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(!strcmp(test_str_b, "B"));
+}