summaryrefslogtreecommitdiffstats
path: root/mojo/public/tests
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-07 06:19:21 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-07 06:19:21 +0000
commit5cdddf5960bc6b5a6331e17007d43f91307d26cd (patch)
tree75689c1f8b61438f1878eba1e7717ff3aa90dd40 /mojo/public/tests
parent91ed28a7325154331b6f6d106fd92f1c29f940c6 (diff)
downloadchromium_src-5cdddf5960bc6b5a6331e17007d43f91307d26cd.zip
chromium_src-5cdddf5960bc6b5a6331e17007d43f91307d26cd.tar.gz
chromium_src-5cdddf5960bc6b5a6331e17007d43f91307d26cd.tar.bz2
Added specialization for bool Array which packs each element into a single bit.
Included some simple tests. R=darin@chromium.org Review URL: https://codereview.chromium.org/76963002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public/tests')
-rw-r--r--mojo/public/tests/bindings_unittest.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/mojo/public/tests/bindings_unittest.cc b/mojo/public/tests/bindings_unittest.cc
new file mode 100644
index 0000000..dc28b550
--- /dev/null
+++ b/mojo/public/tests/bindings_unittest.cc
@@ -0,0 +1,59 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/bindings/lib/bindings.h"
+#include "mojo/public/tests/simple_bindings_support.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace test {
+
+// Tests that basic Array operations work.
+TEST(ArrayTest, Basic) {
+ SimpleBindingsSupport bindings_support;
+
+ // 8 bytes for the array, with 8 bytes left over for elements.
+ internal::FixedBuffer buf(8 + 8*sizeof(char));
+ EXPECT_EQ(16u, buf.size());
+
+ Array<char>::Builder builder(8);
+ EXPECT_EQ(8u, builder.size());
+ for (size_t i = 0; i < builder.size(); ++i) {
+ char val = static_cast<char>(i*2);
+ builder[i] = val;
+ EXPECT_EQ(val, builder.at(i));
+ }
+ Array<char> array = builder.Finish();
+ for (size_t i = 0; i < array.size(); ++i) {
+ char val = static_cast<char>(i) * 2;
+ EXPECT_EQ(val, array[i]);
+ }
+}
+
+// Tests that basic Array<bool> operations work, and that it's packed into 1
+// bit per element.
+TEST(ArrayTest, Bool) {
+ SimpleBindingsSupport bindings_support;
+
+ // 8 bytes for the array header, with 8 bytes left over for elements.
+ internal::FixedBuffer buf(8 + 3);
+ EXPECT_EQ(16u, buf.size());
+
+ // An array of 64 bools can fit into 8 bytes.
+ Array<bool>::Builder builder(64);
+ EXPECT_EQ(64u, builder.size());
+ for (size_t i = 0; i < builder.size(); ++i) {
+ bool val = i % 3 == 0;
+ builder[i] = val;
+ EXPECT_EQ(val, builder.at(i));
+ }
+ Array<bool> array = builder.Finish();
+ for (size_t i = 0; i < array.size(); ++i) {
+ bool val = i % 3 == 0;
+ EXPECT_EQ(val, array[i]);
+ }
+}
+
+} // namespace test
+} // namespace mojo