summaryrefslogtreecommitdiffstats
path: root/mojo/android/javatests
diff options
context:
space:
mode:
authorqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 18:54:04 +0000
committerqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 18:54:04 +0000
commit230db69d88522c52638fe436b35f1314b0b83fe4 (patch)
tree94925144f1f975cf3bcd5cd381d292590c6d6d18 /mojo/android/javatests
parent8bb5a3434d475e98a1bab6d6183096360d3eb67c (diff)
downloadchromium_src-230db69d88522c52638fe436b35f1314b0b83fe4.zip
chromium_src-230db69d88522c52638fe436b35f1314b0b83fe4.tar.gz
chromium_src-230db69d88522c52638fe436b35f1314b0b83fe4.tar.bz2
Helper classes for java bindings.
Review URL: https://codereview.chromium.org/288133005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/android/javatests')
-rw-r--r--mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsHelperTest.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsHelperTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsHelperTest.java
new file mode 100644
index 0000000..a46a157
--- /dev/null
+++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsHelperTest.java
@@ -0,0 +1,55 @@
+// Copyright 2014 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.
+
+package org.chromium.mojo.bindings;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import junit.framework.TestCase;
+
+import java.nio.charset.Charset;
+
+/**
+ * Testing {@link BindingsHelper}.
+ */
+public class BindingsHelperTest extends TestCase {
+
+ /**
+ * Testing {@link BindingsHelper#utf8StringSizeInBytes(String)}.
+ */
+ @SmallTest
+ public void testUTF8StringLength() {
+ String[] stringsToTest = {
+ "",
+ "a",
+ "hello world",
+ "éléphant",
+ "𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕",
+ "你午饭想吃什么",
+ "你午饭想吃什么\0éléphant",
+ };
+ for (String s : stringsToTest) {
+ assertEquals(s.getBytes(Charset.forName("utf8")).length,
+ BindingsHelper.utf8StringSizeInBytes(s));
+ }
+ assertEquals(1, BindingsHelper.utf8StringSizeInBytes("\0"));
+ String s = new StringBuilder().appendCodePoint(0x0).appendCodePoint(0x80).
+ appendCodePoint(0x800).appendCodePoint(0x10000).toString();
+ assertEquals(10, BindingsHelper.utf8StringSizeInBytes(s));
+ assertEquals(10, s.getBytes(Charset.forName("utf8")).length);
+ }
+
+ /**
+ * Testing {@link BindingsHelper#align(int)}.
+ */
+ @SmallTest
+ public void testAlign() {
+ for (int i = 0; i < 3 * BindingsHelper.ALIGNMENT; ++i) {
+ int j = BindingsHelper.align(i);
+ assertTrue(j >= i);
+ assertTrue(j % BindingsHelper.ALIGNMENT == 0);
+ assertTrue(j - i < BindingsHelper.ALIGNMENT);
+ }
+ }
+}