OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_fileutils.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_fileutils.h" |
12 | 12 |
13 #ifdef WIN32 | 13 #ifdef WIN32 |
14 #include <Winsock2.h> | 14 #include <Winsock2.h> |
15 #else | 15 #else |
16 #include <arpa/inet.h> | 16 #include <arpa/inet.h> |
17 #endif | 17 #endif |
18 #include <assert.h> | 18 #include <assert.h> |
19 | 19 |
20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | 20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
21 #include "webrtc/test/testsupport/fileutils.h" | 21 #include "webrtc/test/testsupport/fileutils.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 namespace testing { | 24 namespace testing { |
25 namespace bwe { | 25 namespace bwe { |
26 | 26 |
27 ResourceFileReader::~ResourceFileReader() { | 27 ResourceFileReader::~ResourceFileReader() { |
28 if (file_ != NULL) { | 28 if (file_ != nullptr) { |
29 fclose(file_); | 29 fclose(file_); |
30 file_ = NULL; | 30 file_ = nullptr; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 bool ResourceFileReader::IsAtEnd() { | 34 bool ResourceFileReader::IsAtEnd() { |
35 int32_t current_pos = ftell(file_); | 35 int32_t current_pos = ftell(file_); |
36 fseek(file_, 0, SEEK_END); | 36 fseek(file_, 0, SEEK_END); |
37 int32_t end_pos = ftell(file_); | 37 int32_t end_pos = ftell(file_); |
38 fseek(file_, current_pos, SEEK_SET); | 38 fseek(file_, current_pos, SEEK_SET); |
39 return current_pos == end_pos; | 39 return current_pos == end_pos; |
40 } | 40 } |
41 | 41 |
42 bool ResourceFileReader::Read(uint32_t* out) { | 42 bool ResourceFileReader::Read(uint32_t* out) { |
43 assert(out); | 43 assert(out); |
44 uint32_t tmp = 0; | 44 uint32_t tmp = 0; |
45 if (fread(&tmp, 1, sizeof(uint32_t), file_) != sizeof(uint32_t)) { | 45 if (fread(&tmp, 1, sizeof(uint32_t), file_) != sizeof(uint32_t)) { |
46 printf("Error reading!\n"); | 46 printf("Error reading!\n"); |
47 return false; | 47 return false; |
48 } | 48 } |
49 *out = ntohl(tmp); | 49 *out = ntohl(tmp); |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 ResourceFileReader* ResourceFileReader::Create(const std::string& filename, | 53 ResourceFileReader* ResourceFileReader::Create(const std::string& filename, |
54 const std::string& extension) { | 54 const std::string& extension) { |
55 std::string filepath = webrtc::test::ResourcePath(filename, extension); | 55 std::string filepath = webrtc::test::ResourcePath(filename, extension); |
56 FILE* file = fopen(filepath.c_str(), "rb"); | 56 FILE* file = fopen(filepath.c_str(), "rb"); |
57 if (file == NULL) { | 57 if (file == nullptr) { |
58 BWE_TEST_LOGGING_CONTEXT("ResourceFileReader"); | 58 BWE_TEST_LOGGING_CONTEXT("ResourceFileReader"); |
59 BWE_TEST_LOGGING_LOG1("Create", "Can't read file: %s", filepath.c_str()); | 59 BWE_TEST_LOGGING_LOG1("Create", "Can't read file: %s", filepath.c_str()); |
60 return 0; | 60 return 0; |
61 } else { | 61 } else { |
62 return new ResourceFileReader(file); | 62 return new ResourceFileReader(file); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 OutputFileWriter::~OutputFileWriter() { | 66 OutputFileWriter::~OutputFileWriter() { |
67 if (file_ != NULL) { | 67 if (file_ != nullptr) { |
68 fclose(file_); | 68 fclose(file_); |
69 file_ = NULL; | 69 file_ = nullptr; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 bool OutputFileWriter::Write(uint32_t value) { | 73 bool OutputFileWriter::Write(uint32_t value) { |
74 uint32_t tmp = htonl(value); | 74 uint32_t tmp = htonl(value); |
75 if (fwrite(&tmp, 1, sizeof(uint32_t), file_) != sizeof(uint32_t)) { | 75 if (fwrite(&tmp, 1, sizeof(uint32_t), file_) != sizeof(uint32_t)) { |
76 return false; | 76 return false; |
77 } | 77 } |
78 return true; | 78 return true; |
79 } | 79 } |
80 | 80 |
81 OutputFileWriter* OutputFileWriter::Create(const std::string& filename, | 81 OutputFileWriter* OutputFileWriter::Create(const std::string& filename, |
82 const std::string& extension) { | 82 const std::string& extension) { |
83 std::string filepath = webrtc::test::OutputPath() + filename + "." + | 83 std::string filepath = webrtc::test::OutputPath() + filename + "." + |
84 extension; | 84 extension; |
85 FILE* file = fopen(filepath.c_str(), "wb"); | 85 FILE* file = fopen(filepath.c_str(), "wb"); |
86 if (file == NULL) { | 86 if (file == nullptr) { |
87 BWE_TEST_LOGGING_CONTEXT("OutputFileWriter"); | 87 BWE_TEST_LOGGING_CONTEXT("OutputFileWriter"); |
88 BWE_TEST_LOGGING_LOG1("Create", "Can't write file: %s", filepath.c_str()); | 88 BWE_TEST_LOGGING_LOG1("Create", "Can't write file: %s", filepath.c_str()); |
89 return NULL; | 89 return nullptr; |
90 } else { | 90 } else { |
91 return new OutputFileWriter(file); | 91 return new OutputFileWriter(file); |
92 } | 92 } |
93 } | 93 } |
94 } // namespace bwe | 94 } // namespace bwe |
95 } // namespace testing | 95 } // namespace testing |
96 } // namespace webrtc | 96 } // namespace webrtc |
OLD | NEW |