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

Side by Side Diff: mojo/go/tests/system_test.go

Issue 664163004: -Go bindings for creating/managing shared buffers between applications (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Go build patches Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « build/go/rules.gni ('k') | mojo/public/go/system/core.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package tests 5 package tests
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "testing"
10 "unsafe"
11
9 "mojo/go/system/embedder" 12 "mojo/go/system/embedder"
10 "mojo/public/go/system" 13 "mojo/public/go/system"
11 m "mojo/public/go/system/impl" 14 m "mojo/public/go/system/impl"
12 "testing"
13 ) 15 )
14 16
15 var core system.Core 17 var core system.Core
16 18
17 func init() { 19 func init() {
18 embedder.InitializeMojoEmbedder() 20 embedder.InitializeMojoEmbedder()
19 core = m.GetCore() 21 core = m.GetCore()
20 } 22 }
21 23
22 func TestGetTimeTicksNow(t *testing.T) { 24 func TestGetTimeTicksNow(t *testing.T) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if r = core.Close(hp); r != m.MOJO_RESULT_OK { 109 if r = core.Close(hp); r != m.MOJO_RESULT_OK {
108 t.Fatalf("Close on hp failed:%v", r) 110 t.Fatalf("Close on hp failed:%v", r)
109 } 111 }
110 if r = core.Wait(hc, m.MOJO_HANDLE_SIGNAL_READABLE, 100); r != m.MOJO_RE SULT_FAILED_PRECONDITION { 112 if r = core.Wait(hc, m.MOJO_HANDLE_SIGNAL_READABLE, 100); r != m.MOJO_RE SULT_FAILED_PRECONDITION {
111 t.Fatalf("hc should not be readable after hp closed:%v", r) 113 t.Fatalf("hc should not be readable after hp closed:%v", r)
112 } 114 }
113 if r = core.Close(hc); r != m.MOJO_RESULT_OK { 115 if r = core.Close(hc); r != m.MOJO_RESULT_OK {
114 t.Fatalf("Close on hc failed:%v", r) 116 t.Fatalf("Close on hc failed:%v", r)
115 } 117 }
116 } 118 }
119
120 func TestSharedBuffer(t *testing.T) {
121 var h0, h1 m.MojoHandle
122 var bufPtr unsafe.Pointer
123 var r m.MojoResult
124
125 if r, h0 = core.CreateSharedBuffer(nil, 100); r != m.MOJO_RESULT_OK {
126 t.Fatalf("CreateSharedBuffer failed:%v", r)
127 }
128 if h0 == m.MOJO_HANDLE_INVALID {
129 t.Fatalf("CreateSharedBuffer returned an invalid handle h0:%v", h0)
130 }
131 if r, bufPtr = core.MapBuffer(h0, 0, 100, m.MOJO_MAP_BUFFER_FLAG_NONE); r != m.MOJO_RESULT_OK {
132 t.Fatalf("MapBuffer failed to map buffer with h0:%v", r)
133 }
134 bufArrayh0 := (*[100]byte)(bufPtr)
135 bufArrayh0[50] = 'x'
136 if r, h1 = core.DuplicateBufferHandle(h0, nil); r != m.MOJO_RESULT_OK {
137 t.Fatalf("DuplicateBufferHandle of h0 failed:%v", r)
138 }
139 if h1 == m.MOJO_HANDLE_INVALID {
140 t.Fatalf("DuplicateBufferHandle returned an invalid handle h1:%v ", h1)
141 }
142 if r = core.Close(h0); r != m.MOJO_RESULT_OK {
143 t.Fatalf("Close on h0 failed:%v", r)
144 }
145 bufArrayh0[51] = 'y'
146 if r = core.UnmapBuffer(bufPtr); r != m.MOJO_RESULT_OK {
147 t.Fatalf("UnmapBuffer failed:%v", r)
148 }
149 if r, bufPtr = core.MapBuffer(h1, 50, 50, m.MOJO_MAP_BUFFER_FLAG_NONE); r != m.MOJO_RESULT_OK {
150 t.Fatalf("MapBuffer failed to map buffer with h1:%v", r)
151 }
152 bufArrayh1 := (*[50]byte)(bufPtr)
153 if bufArrayh1[0] != 'x' || bufArrayh1[1] != 'y' {
154 t.Fatalf("Failed to validate shared buffer. expected:x,y got:%s, %s", bufArrayh1[0], bufArrayh1[1])
155 }
156 if r = core.UnmapBuffer(bufPtr); r != m.MOJO_RESULT_OK {
157 t.Fatalf("UnmapBuffer failed:%v", r)
158 }
159 if r = core.Close(h1); r != m.MOJO_RESULT_OK {
160 t.Fatalf("Close on h1 failed:%v", r)
161 }
162 }
OLDNEW
« no previous file with comments | « build/go/rules.gni ('k') | mojo/public/go/system/core.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698