Fix Win64 warnings
This change fixes warnings about converting size_t to int.
BUG=webrtc:1323
TEST=trybots passing
Review URL: https://webrtc-codereview.appspot.com/1064004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@3419 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc b/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc
index 7df551e..83c940a 100644
--- a/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc
+++ b/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc
@@ -80,7 +80,7 @@
return 0;
}
-int SequenceCoder(webrtc::test::CommandLineParser parser) {
+int SequenceCoder(webrtc::test::CommandLineParser& parser) {
int width = strtol((parser.GetFlag("w")).c_str(), NULL, 10);
int height = strtol((parser.GetFlag("h")).c_str(), NULL, 10);
int framerate = strtol((parser.GetFlag("f")).c_str(), NULL, 10);
diff --git a/webrtc/test/test.gyp b/webrtc/test/test.gyp
index 3f90b70..304e532 100644
--- a/webrtc/test/test.gyp
+++ b/webrtc/test/test.gyp
@@ -16,19 +16,16 @@
'target_name': 'test_support',
'type': 'static_library',
'include_dirs': [
+ # TODO(kjellander): Remove this by making all includes use full paths.
'.',
],
- 'direct_dependent_settings': {
- 'include_dirs': [
- '.', # Some includes are hierarchical
- ],
- },
'dependencies': [
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/testing/gmock.gyp:gmock',
],
'all_dependent_settings': {
'include_dirs': [
+ # TODO(kjellander): Remove this by making all includes use full paths.
'.',
],
},
diff --git a/webrtc/test/testsupport/gtest_prod_util.h b/webrtc/test/testsupport/gtest_prod_util.h
index 7d123a8..ec3cce6 100644
--- a/webrtc/test/testsupport/gtest_prod_util.h
+++ b/webrtc/test/testsupport/gtest_prod_util.h
@@ -12,7 +12,7 @@
#define WEBRTC_TEST_TESTSUPPORT_GTEST_PROD_UTIL_H_
#pragma once
-#include "gtest/gtest_prod.h"
+#include "testing/gtest/include/gtest/gtest_prod.h"
// This file is a plain copy of Chromium's base/gtest_prod_util.h.
//
diff --git a/webrtc/test/testsupport/metrics/video_metrics.cc b/webrtc/test/testsupport/metrics/video_metrics.cc
index 97663f3..edf898c 100644
--- a/webrtc/test/testsupport/metrics/video_metrics.cc
+++ b/webrtc/test/testsupport/metrics/video_metrics.cc
@@ -10,7 +10,7 @@
#include "testsupport/metrics/video_metrics.h"
-#include <algorithm> // min_element, max_element
+#include <algorithm> // min_element, max_element
#include <cassert>
#include <cstdio>
@@ -24,9 +24,9 @@
double kMetricsPerfectPSNR = kPerfectPSNR;
// Used for calculating min and max values.
-static bool LessForFrameResultValue (const FrameResult& s1,
- const FrameResult& s2) {
- return s1.value < s2.value;
+static bool LessForFrameResultValue(const FrameResult& s1,
+ const FrameResult& s2) {
+ return s1.value < s2.value;
}
enum VideoMetricsType { kPSNR, kSSIM, kBoth };
@@ -107,7 +107,7 @@
int frame_number = 0;
// Read reference and test frames.
- const int frame_length = 3 * width * height >> 1;
+ const size_t frame_length = 3 * width * height >> 1;
I420VideoFrame ref_frame;
I420VideoFrame test_frame;
scoped_array<uint8_t> ref_buffer(new uint8_t[frame_length]);
@@ -118,8 +118,8 @@
ref_frame.CreateEmptyFrame(width, height, width, half_width, half_width);
test_frame.CreateEmptyFrame(width, height, width, half_width, half_width);
- int ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp);
- int test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp);
+ size_t ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp);
+ size_t test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp);
while (ref_bytes == frame_length && test_bytes == frame_length) {
// Converting from buffer to plane representation.
ConvertToI420(kI420, ref_buffer.get(), 0, 0, width, height, 0,
diff --git a/webrtc/tools/frame_analyzer/video_quality_analysis.cc b/webrtc/tools/frame_analyzer/video_quality_analysis.cc
index 8314e91..c38ad84 100644
--- a/webrtc/tools/frame_analyzer/video_quality_analysis.cc
+++ b/webrtc/tools/frame_analyzer/video_quality_analysis.cc
@@ -20,6 +20,8 @@
namespace webrtc {
namespace test {
+using std::string;
+
int GetI420FrameSize(int width, int height) {
int half_width = (width + 1) >> 1;
int half_height = (height + 1) >> 1;
@@ -32,14 +34,14 @@
}
int ExtractFrameSequenceNumber(std::string line) {
- int space_position = line.find(' ');
- if (space_position == -1) {
+ size_t space_position = line.find(' ');
+ if (space_position == string::npos) {
return -1;
}
std::string frame = line.substr(0, space_position);
- int underscore_position = frame.find('_');
- if (underscore_position == -1) {
+ size_t underscore_position = frame.find('_');
+ if (underscore_position == string::npos) {
return -1;
}
std::string frame_number = frame.substr(underscore_position + 1);
@@ -48,8 +50,8 @@
}
int ExtractDecodedFrameNumber(std::string line) {
- int space_position = line.find(' ');
- if (space_position == -1) {
+ size_t space_position = line.find(' ');
+ if (space_position == string::npos) {
return -1;
}
std::string decoded_number = line.substr(space_position + 1);
@@ -58,8 +60,8 @@
}
bool IsThereBarcodeError(std::string line) {
- int barcode_error_position = line.find("Barcode error");
- if (barcode_error_position != -1) {
+ size_t barcode_error_position = line.find("Barcode error");
+ if (barcode_error_position != string::npos) {
return true;
}
return false;
diff --git a/webrtc/tools/simple_command_line_parser.cc b/webrtc/tools/simple_command_line_parser.cc
index 0ad5e60..d7757ed 100644
--- a/webrtc/tools/simple_command_line_parser.cc
+++ b/webrtc/tools/simple_command_line_parser.cc
@@ -8,43 +8,39 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "tools/simple_command_line_parser.h"
+#include "webrtc/tools/simple_command_line_parser.h"
#include <cstdio>
#include <cstdlib>
+#include <string>
namespace webrtc {
namespace test {
+using std::string;
+
void CommandLineParser::Init(int argc, char** argv) {
args_ = std::vector<std::string> (argv + 1, argv + argc);
}
bool CommandLineParser::IsStandaloneFlag(std::string flag) {
- int equal_pos = flag.find("=");
-
- if (equal_pos < 0) {
- return true;
- }
- return false;
+ return flag.find("=") == string::npos;
}
bool CommandLineParser::IsFlagWellFormed(std::string flag) {
- int dash_pos = flag.find("--");
- int equal_pos = flag.find("=");
-
+ size_t dash_pos = flag.find("--");
+ size_t equal_pos = flag.find("=");
if (dash_pos != 0) {
fprintf(stderr, "Wrong switch format: %s\n", flag.c_str());
fprintf(stderr, "Flag doesn't start with --\n");
return false;
}
-
- int flag_length = flag.length() - 1;
+ size_t flag_length = flag.length() - 1;
// We use 3 here because we assume that the flags are in the format
// --flag_name=flag_value, thus -- are at positions 0 and 1 and we should have
- // at least one symbor for the flag name.
- if (equal_pos >= 0 && (equal_pos < 3 || equal_pos == flag_length)) {
+ // at least one symbol for the flag name.
+ if (equal_pos > 0 && (equal_pos < 3 || equal_pos == flag_length)) {
fprintf(stderr, "Wrong switch format: %s\n", flag.c_str());
fprintf(stderr, "Wrong placement of =\n");
return false;
@@ -53,20 +49,22 @@
}
std::string CommandLineParser::GetCommandLineFlagName(std::string flag) {
- int dash_pos = flag.find("--");
- int equal_pos = flag.find("=");
-
- if (equal_pos < 0) {
- return flag.substr(dash_pos+2);
+ size_t dash_pos = flag.find("--");
+ size_t equal_pos = flag.find("=");
+ if (equal_pos == string::npos) {
+ return flag.substr(dash_pos + 2);
} else {
- return flag.substr(dash_pos+2, equal_pos-2);
+ return flag.substr(dash_pos + 2, equal_pos - 2);
}
}
std::string CommandLineParser::GetCommandLineFlagValue(std::string flag) {
- int equal_pos = flag.find("=");
-
- return flag.substr(equal_pos+1);
+ size_t equal_pos = flag.find("=");
+ if (equal_pos == string::npos) {
+ return "";
+ } else {
+ return flag.substr(equal_pos + 1);
+ }
}
void CommandLineParser::PrintEnteredFlags() {
@@ -112,14 +110,15 @@
fprintf(stdout, "%s", usage_message_.c_str());
}
-void CommandLineParser::SetFlag(std::string flag_name, std::string flag_value) {
- flags_[flag_name] = flag_value;
+void CommandLineParser::SetFlag(std::string flag_name,
+ std::string default_flag_value) {
+ flags_[flag_name] = default_flag_value;
}
std::string CommandLineParser::GetFlag(std::string flag_name) {
std::map<std::string, std::string>::iterator flag_iter;
flag_iter = flags_.find(flag_name);
- // If no such file.
+ // If no such flag.
if (flag_iter == flags_.end()) {
return "";
}
diff --git a/webrtc/tools/simple_command_line_parser.h b/webrtc/tools/simple_command_line_parser.h
index 31cac65..3ccfb0c 100644
--- a/webrtc/tools/simple_command_line_parser.h
+++ b/webrtc/tools/simple_command_line_parser.h
@@ -15,9 +15,19 @@
#include <map>
#include <vector>
+#include "system_wrappers/interface/constructor_magic.h"
+#include "test/testsupport/gtest_prod_util.h"
+
// This is a very basic command line parsing class. We pass the command line
// arguments and their number and the class forms a vector out of these. Than we
// should set up the flags - we provide a name and a string value and map these.
+//
+// Example use of this class:
+// 1. Create a CommandLineParser object.
+// 2. Configure the flags you want to support with SetFlag calls.
+// 3. Call Init with your program's argc+argv parameters.
+// 4. Parse the flags by calling ProcessFlags.
+// 5. Get the values of the flags using GetFlag.
namespace webrtc {
namespace test {
@@ -44,9 +54,13 @@
void PrintUsageMessage();
// Set a flag into the map of flag names/values.
- void SetFlag(std::string flag_name, std::string flag_value);
+ // To set a boolean flag, use "false" as the default flag value.
+ // The flag_name should not include the -- prefix.
+ void SetFlag(std::string flag_name, std::string default_flag_value);
- // Gets a flag when provided a flag name. Returns "" if the flag is unknown.
+ // Gets a flag when provided a flag name (name is without the -- prefix).
+ // Returns "" if the flag is unknown and "true"/"false" if the flag is a
+ // boolean flag.
std::string GetFlag(std::string flag_name);
private:
@@ -61,14 +75,23 @@
// understand e.g. --standalone (in contrast to --non_standalone=1).
bool IsStandaloneFlag(std::string flag);
- // Checks weather the flag is in the format --flag_name=flag_value.
+ // Checks whether the flag is in the format --flag_name=flag_value.
+ // or just --flag_name.
bool IsFlagWellFormed(std::string flag);
- // Extracts the flag name from the flag.
+ // Extracts the flag name from the flag, i.e. return foo for --foo=bar.
std::string GetCommandLineFlagName(std::string flag);
- // Extracts the falg value from the flag.
+ // Extracts the flag value from the flag, i.e. return bar for --foo=bar.
+ // If the flag has no value (i.e. no equals sign) an empty string is returned.
std::string GetCommandLineFlagValue(std::string flag);
+
+ FRIEND_TEST_ALL_PREFIXES(CommandLineParserTest, IsStandaloneFlag);
+ FRIEND_TEST_ALL_PREFIXES(CommandLineParserTest, IsFlagWellFormed);
+ FRIEND_TEST_ALL_PREFIXES(CommandLineParserTest, GetCommandLineFlagName);
+ FRIEND_TEST_ALL_PREFIXES(CommandLineParserTest, GetCommandLineFlagValue);
+
+ DISALLOW_COPY_AND_ASSIGN(CommandLineParser);
};
} // namespace test
diff --git a/webrtc/tools/simple_command_line_parser_unittest.cc b/webrtc/tools/simple_command_line_parser_unittest.cc
new file mode 100644
index 0000000..dbf6239
--- /dev/null
+++ b/webrtc/tools/simple_command_line_parser_unittest.cc
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "gtest/gtest.h"
+#include "webrtc/tools/simple_command_line_parser.h"
+
+namespace webrtc {
+namespace test {
+
+class CommandLineParserTest : public ::testing::Test {
+ protected:
+ virtual void SetUp() {
+ parser_ = new CommandLineParser();
+
+ test_flags_length_ = 3;
+ int flag_size = 32;
+ test_flags_ = new char*[test_flags_length_];
+ for (int i = 0; i < test_flags_length_; ++i) {
+ test_flags_[i] = new char[flag_size];
+ }
+ strncpy(test_flags_[0], "tools_unittest", flag_size);
+ strncpy(test_flags_[1], "--foo", flag_size);
+ strncpy(test_flags_[2], "--bar=1", flag_size);
+ }
+ virtual void TearDown() {
+ for (int i = 0; i < test_flags_length_; ++i) {
+ delete[] test_flags_[i];
+ }
+ delete[] test_flags_;
+ delete parser_;
+ }
+ CommandLineParser* parser_;
+ // Test flags to emulate a program's argv arguments.
+ char** test_flags_;
+ int test_flags_length_;
+};
+
+TEST_F(CommandLineParserTest, ProcessFlags) {
+ // Setup supported flags to parse.
+ parser_->SetFlag("foo", "false");
+ parser_->SetFlag("foo-foo", "false"); // To test boolean flags defaults.
+ parser_->SetFlag("bar", "222");
+ parser_->SetFlag("baz", "333"); // To test the default value functionality.
+
+ parser_->Init(test_flags_length_, test_flags_);
+ parser_->ProcessFlags();
+ EXPECT_EQ("true", parser_->GetFlag("foo"));
+ EXPECT_EQ("false", parser_->GetFlag("foo-foo"));
+ EXPECT_EQ("1", parser_->GetFlag("bar"));
+ EXPECT_EQ("333", parser_->GetFlag("baz"));
+ EXPECT_EQ("", parser_->GetFlag("unknown"));
+}
+
+TEST_F(CommandLineParserTest, IsStandaloneFlag) {
+ EXPECT_TRUE(parser_->IsStandaloneFlag("--foo"));
+ EXPECT_TRUE(parser_->IsStandaloneFlag("--foo-foo"));
+ EXPECT_FALSE(parser_->IsStandaloneFlag("--foo=1"));
+}
+
+TEST_F(CommandLineParserTest, IsFlagWellFormed) {
+ EXPECT_TRUE(parser_->IsFlagWellFormed("--foo"));
+ EXPECT_TRUE(parser_->IsFlagWellFormed("--foo-foo"));
+ EXPECT_TRUE(parser_->IsFlagWellFormed("--bar=1"));
+}
+
+TEST_F(CommandLineParserTest, GetCommandLineFlagName) {
+ EXPECT_EQ("foo", parser_->GetCommandLineFlagName("--foo"));
+ EXPECT_EQ("foo-foo", parser_->GetCommandLineFlagName("--foo-foo"));
+ EXPECT_EQ("bar", parser_->GetCommandLineFlagName("--bar=1"));
+}
+
+TEST_F(CommandLineParserTest, GetCommandLineFlagValue) {
+ EXPECT_EQ("", parser_->GetCommandLineFlagValue("--foo"));
+ EXPECT_EQ("", parser_->GetCommandLineFlagValue("--foo-foo"));
+ EXPECT_EQ("1", parser_->GetCommandLineFlagValue("--bar=1"));
+}
+
+} // namespace test
+} // namespace webrtc
+
diff --git a/webrtc/tools/tools.gyp b/webrtc/tools/tools.gyp
index a678734..48949ed 100644
--- a/webrtc/tools/tools.gyp
+++ b/webrtc/tools/tools.gyp
@@ -14,14 +14,6 @@
{
'target_name': 'command_line_parser',
'type': 'static_library',
- 'include_dirs': [
- '.',
- ],
- 'direct_dependent_settings': {
- 'include_dirs': [
- '.',
- ],
- },
'sources': [
'simple_command_line_parser.h',
'simple_command_line_parser.cc',
@@ -114,11 +106,13 @@
'target_name': 'tools_unittests',
'type': 'executable',
'dependencies': [
+ 'command_line_parser',
'frame_editing_lib',
'<(webrtc_root)/test/test.gyp:test_support_main',
'<(DEPTH)/testing/gtest.gyp:gtest',
],
'sources': [
+ 'simple_command_line_parser_unittest.cc',
'frame_editing/frame_editing_unittest.cc',
],
}, # tools_unittests