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

Side by Side Diff: runtime/bin/file_test.cc

Issue 11348006: Remove file name from File C++ structure. It is not used. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/file_win.cc » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart 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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/file.h" 5 #include "bin/file.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 10
11 // Helper method to be able to run the test from the runtime 11 // Helper method to be able to run the test from the runtime
12 // directory, or the top directory. 12 // directory, or the top directory.
13 static const char* GetFileName(const char* name) { 13 static const char* GetFileName(const char* name) {
14 if (File::Exists(name)) { 14 if (File::Exists(name)) {
15 return name; 15 return name;
16 } else { 16 } else {
17 static const int kRuntimeLength = strlen("runtime/"); 17 static const int kRuntimeLength = strlen("runtime/");
18 return name + kRuntimeLength; 18 return name + kRuntimeLength;
19 } 19 }
20 } 20 }
21 21
22 22
23 UNIT_TEST_CASE(Read) { 23 UNIT_TEST_CASE(Read) {
24 const char* kFilename = GetFileName("runtime/bin/file_test.cc"); 24 const char* kFilename = GetFileName("runtime/bin/file_test.cc");
25 File* file = File::Open(kFilename, File::kRead); 25 File* file = File::Open(kFilename, File::kRead);
26 EXPECT(file != NULL); 26 EXPECT(file != NULL);
27 EXPECT_STREQ(kFilename, file->name());
28 char buffer[16]; 27 char buffer[16];
29 buffer[0] = '\0'; 28 buffer[0] = '\0';
30 EXPECT(file->ReadFully(buffer, 13)); // ReadFully returns true. 29 EXPECT(file->ReadFully(buffer, 13)); // ReadFully returns true.
31 buffer[13] = '\0'; 30 buffer[13] = '\0';
32 EXPECT_STREQ("// Copyright ", buffer); 31 EXPECT_STREQ("// Copyright ", buffer);
33 EXPECT(!file->WriteByte(1)); // Cannot write to a read-only file. 32 EXPECT(!file->WriteByte(1)); // Cannot write to a read-only file.
34 delete file; 33 delete file;
35 } 34 }
36 35
37 36
(...skipping 12 matching lines...) Expand all
50 const char* kFilename = 49 const char* kFilename =
51 GetFileName("runtime/tests/vm/data/fixed_length_file"); 50 GetFileName("runtime/tests/vm/data/fixed_length_file");
52 File* file = File::Open(kFilename, File::kRead); 51 File* file = File::Open(kFilename, File::kRead);
53 EXPECT(file != NULL); 52 EXPECT(file != NULL);
54 EXPECT(file->ReadFully(buf, 12)); 53 EXPECT(file->ReadFully(buf, 12));
55 EXPECT_EQ(12, file->Position()); 54 EXPECT_EQ(12, file->Position());
56 EXPECT(file->ReadFully(buf, 6)); 55 EXPECT(file->ReadFully(buf, 6));
57 EXPECT_EQ(18, file->Position()); 56 EXPECT_EQ(18, file->Position());
58 delete file; 57 delete file;
59 } 58 }
OLDNEW
« no previous file with comments | « runtime/bin/file_macos.cc ('k') | runtime/bin/file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698