Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/test/testsupport/isolated_output.h" | |
| 12 | |
| 13 #include <string.h> | |
| 14 | |
| 15 #include <string> | |
| 16 | |
| 17 #include "gflags/gflags.h" | |
| 18 #include "webrtc/base/file.h" | |
| 19 #include "webrtc/base/pathutils.h" | |
| 20 #include "webrtc/test/gtest.h" | |
| 21 | |
| 22 DECLARE_string(isolated_out_dir); | |
| 23 | |
| 24 namespace webrtc { | |
| 25 namespace test { | |
| 26 | |
| 27 TEST(IsolatedOutputTest, ShouldRejectInvalidIsolatedOutDir) { | |
| 28 std::string backup = FLAGS_isolated_out_dir; | |
| 29 FLAGS_isolated_out_dir = ""; | |
| 30 ASSERT_FALSE(WriteIsolatedOutput("a-file", "some-contents")); | |
| 31 FLAGS_isolated_out_dir = backup; | |
| 32 } | |
| 33 | |
| 34 TEST(IsolatedOutputTest, ShouldRejectInvalidFileName) { | |
| 35 ASSERT_FALSE(WriteIsolatedOutput(nullptr, "some-contents")); | |
| 36 ASSERT_FALSE(WriteIsolatedOutput("", "some-contents")); | |
| 37 } | |
| 38 | |
| 39 // Sets isolated_out_dir=<a-writable-path> to execute this test. | |
| 40 TEST(IsolatedOutputTest, ShouldBeAbleToWriteContent) { | |
| 41 const char* filename = "a-file"; | |
| 42 const char* content = "some-contents"; | |
| 43 if (WriteIsolatedOutput(filename, content)) { | |
| 44 rtc::File input = | |
| 45 rtc::File::Open(rtc::Pathname(FLAGS_isolated_out_dir, filename)); | |
| 46 ASSERT_TRUE(input.IsOpen()); | |
| 47 ASSERT_TRUE(input.Seek(0)); | |
| 48 uint8_t buffer[32]; | |
| 49 ASSERT_EQ(input.Read(buffer, strlen(content)), strlen(content)); | |
| 50 buffer[strlen(content)] = 0; | |
| 51 ASSERT_EQ(std::string(content), | |
| 52 std::string(reinterpret_cast<char*>(buffer))); | |
| 53 } | |
|
kjellander_webrtc
2016/12/08 11:51:28
Please add cleaning of the file and ensure it alwa
Hzj_jie
2016/12/08 23:01:09
Done.
| |
| 54 } | |
| 55 | |
| 56 } // namespace test | |
| 57 } // namespace webrtc | |
| OLD | NEW |