Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1247)

Unified Diff: mojo/public/c/bindings/tests/buffer_unittest.cc

Issue 2062323002: Mojo C bindings library pt1: MojomBuffer (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/c/bindings/tests/buffer_unittest.cc
diff --git a/mojo/public/c/bindings/tests/buffer_unittest.cc b/mojo/public/c/bindings/tests/buffer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..014a7988b85e43dddcc6f549dfe3b0301e90f16c
--- /dev/null
+++ b/mojo/public/c/bindings/tests/buffer_unittest.cc
@@ -0,0 +1,38 @@
+// Copyright 2016 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/c/bindings/buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
viettrungluu 2016/06/15 15:00:58 nit: blank line above
vardhan 2016/06/15 15:48:00 Done.
+
+namespace {
+
+TEST(MojomBufferTest, Alignment) {
+ char buffer[100];
+ struct MojomBuffer mbuf = {
+ buffer, sizeof(buffer),
+ 0, // num_bytes_used
+ };
+
+ // This should actually allocate 8 bytes:
+ EXPECT_EQ(buffer, MojomBuffer_Allocate(&mbuf, 6));
+ EXPECT_EQ(8ul, mbuf.num_bytes_used);
+ // The start of the next buffer is buffer + 8 bytes:
+ EXPECT_EQ(buffer + 8, MojomBuffer_Allocate(&mbuf, 6));
+ EXPECT_EQ(16ul, mbuf.num_bytes_used);
+}
viettrungluu 2016/06/15 15:00:58 You should test that allocating things that are al
vardhan 2016/06/15 15:48:00 Done.
+
+TEST(MojomBufferTest, Failure) {
viettrungluu 2016/06/15 15:00:58 You should really test the subtle part, namely the
vardhan 2016/06/15 15:48:00 Done.
+ char buffer[100];
+ struct MojomBuffer mbuf = {
+ buffer, sizeof(buffer),
+ 0, // num_bytes_used
+ };
+
+ // Allocate too much space.
+ EXPECT_EQ(NULL, MojomBuffer_Allocate(&mbuf, sizeof(buffer) + 10));
+ // Allocating 0 bytes should fail as well.
viettrungluu 2016/06/15 15:00:58 Why should it necessarily be a failure?
vardhan 2016/06/15 15:48:00 (see other comment)
+ EXPECT_EQ(NULL, MojomBuffer_Allocate(&mbuf, 0));
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698