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

Side by Side Diff: tests/ffi/ffi_timeofday_test.dart

Issue 1209033003: Work in progres, please take a look and give early feedback if this is the way we want to structure… (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: indentation Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Fletch project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Fletch project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 import 'dart:ffi'; 5 import 'dart:ffi';
6 import 'dart:io' as io; 6 import 'dart:io' as io;
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 8
9 abstract class Timeval implements Foreign { 9 abstract class Timeval implements ForeignMemory {
10 factory Timeval() { 10 factory Timeval() {
11 switch (Foreign.bitsPerMachineWord) { 11 switch (Foreign.bitsPerMachineWord) {
12 case 32: return new Timeval32(); 12 case 32: return new Timeval32();
13 case 64: return new Timeval64(); 13 case 64: return new Timeval64();
14 default: throw "Unsupported machine word size."; 14 default: throw "Unsupported machine word size.";
15 } 15 }
16 } 16 }
17 int get tv_sec; 17 int get tv_sec;
18 int get tv_usec; 18 int get tv_usec;
19 } 19 }
20 20
21 class Timeval32 extends Foreign implements Timeval { 21 class Timeval32 extends ForeignMemory implements Timeval {
22 Timeval32() : super.allocated(8); 22 Timeval32() : super.allocated(8);
23 int get tv_sec => getInt32(0); 23 int get tv_sec => getInt32(0);
24 int get tv_usec => getInt32(4); 24 int get tv_usec => getInt32(4);
25 } 25 }
26 26
27 class Timeval64 extends Foreign implements Timeval { 27 class Timeval64 extends ForeignMemory implements Timeval {
28 Timeval64() : super.allocated(16); 28 Timeval64() : super.allocated(16);
29 int get tv_sec => getInt64(0); 29 int get tv_sec => getInt64(0);
30 int get tv_usec => getInt64(8); 30 int get tv_usec => getInt64(8);
31 } 31 }
32 32
33 final Foreign gettimeofday = Foreign.lookup('gettimeofday'); 33 final ForeignFunction gettimeofday =
34 ForeignLibrary.standard.lookup('gettimeofday');
34 35
35 main() { 36 main() {
36 Timeval timeval = new Timeval(); 37 Timeval timeval = new Timeval();
37 Expect.equals(0, gettimeofday.icall$2(timeval, 0)); 38 Expect.equals(0, gettimeofday.icall$2(timeval, 0));
38 int start = timeval.tv_sec * 1000 + timeval.tv_usec ~/ 1000; 39 int start = timeval.tv_sec * 1000 + timeval.tv_usec ~/ 1000;
39 40
40 int sleepTime = 300; 41 int sleepTime = 300;
41 io.sleep(sleepTime); 42 io.sleep(sleepTime);
42 43
43 Expect.equals(0, gettimeofday.icall$2(timeval, 0)); 44 Expect.equals(0, gettimeofday.icall$2(timeval, 0));
44 int end = timeval.tv_sec * 1000 + timeval.tv_usec ~/ 1000; 45 int end = timeval.tv_sec * 1000 + timeval.tv_usec ~/ 1000;
45 Expect.isTrue((end - start) >= sleepTime); 46 Expect.isTrue((end - start) >= sleepTime);
46 timeval.free(); 47 timeval.free();
47 } 48 }
OLDNEW
« tests/ffi/ffi_test.dart ('K') | « tests/ffi/ffi_test.dart ('k') | tests/io/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698