blob: fb577610fbbcc9d5159ec3b218bbb8b3375dcaf0 [file] [log] [blame]
zijiehe2769ec62016-12-14 23:03:031/*
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
Edward Lemuraf8659a2017-09-27 12:46:2411#include "test/testsupport/test_artifacts.h"
zijiehe2769ec62016-12-14 23:03:0312
13#include <string.h>
Jonas Olssona4d87372019-07-05 17:08:3314
zijiehe2769ec62016-12-14 23:03:0315#include <string>
16
Artem Titov506d4eb2020-06-05 15:04:2617#include "absl/flags/declare.h"
Mirko Bonadei2ab97f62019-07-18 11:44:1218#include "absl/flags/flag.h"
Niels Möllerb7edf692019-02-08 15:40:5319#include "rtc_base/system/file_wrapper.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "test/gtest.h"
Steve Anton10542f22019-01-11 17:11:0021#include "test/testsupport/file_utils.h"
zijiehe2769ec62016-12-14 23:03:0322
Mirko Bonadei2ab97f62019-07-18 11:44:1223ABSL_DECLARE_FLAG(std::string, test_artifacts_dir);
zijiehe2769ec62016-12-14 23:03:0324
25namespace webrtc {
26namespace test {
27
28TEST(IsolatedOutputTest, ShouldRejectInvalidIsolatedOutDir) {
Mirko Bonadei2ab97f62019-07-18 11:44:1229 const std::string backup = absl::GetFlag(FLAGS_test_artifacts_dir);
30 absl::SetFlag(&FLAGS_test_artifacts_dir, "");
Edward Lemuraf8659a2017-09-27 12:46:2431 ASSERT_FALSE(WriteToTestArtifactsDir("a-file", "some-contents"));
Mirko Bonadei2ab97f62019-07-18 11:44:1232 absl::SetFlag(&FLAGS_test_artifacts_dir, backup);
zijiehe2769ec62016-12-14 23:03:0333}
34
35TEST(IsolatedOutputTest, ShouldRejectInvalidFileName) {
Edward Lemuraf8659a2017-09-27 12:46:2436 ASSERT_FALSE(WriteToTestArtifactsDir(nullptr, "some-contents"));
37 ASSERT_FALSE(WriteToTestArtifactsDir("", "some-contents"));
zijiehe2769ec62016-12-14 23:03:0338}
39
40// Sets isolated_out_dir=<a-writable-path> to execute this test.
41TEST(IsolatedOutputTest, ShouldBeAbleToWriteContent) {
42 const char* filename = "a-file";
43 const char* content = "some-contents";
Edward Lemuraf8659a2017-09-27 12:46:2444 if (WriteToTestArtifactsDir(filename, content)) {
Mirko Bonadei2ab97f62019-07-18 11:44:1245 std::string out_file =
46 JoinFilename(absl::GetFlag(FLAGS_test_artifacts_dir), filename);
Niels Möllerb7edf692019-02-08 15:40:5347 FileWrapper input = FileWrapper::OpenReadOnly(out_file);
48 EXPECT_TRUE(input.is_open());
49 EXPECT_TRUE(input.Rewind());
zijiehe2769ec62016-12-14 23:03:0350 uint8_t buffer[32];
51 EXPECT_EQ(input.Read(buffer, strlen(content)), strlen(content));
52 buffer[strlen(content)] = 0;
53 EXPECT_EQ(std::string(content),
54 std::string(reinterpret_cast<char*>(buffer)));
55 input.Close();
56
Niels Möllerb7edf692019-02-08 15:40:5357 EXPECT_TRUE(RemoveFile(out_file));
zijiehe2769ec62016-12-14 23:03:0358 }
59}
60
61} // namespace test
62} // namespace webrtc