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
This commit is contained in:
kjellander@webrtc.org 2013-01-26 16:36:40 +00:00
parent 8526459a2e
commit b2d7497faf
9 changed files with 163 additions and 61 deletions

View File

@ -80,7 +80,7 @@ int Vp8SequenceCoderDecodeCallback::Decoded(webrtc::I420VideoFrame& image) {
return 0; 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 width = strtol((parser.GetFlag("w")).c_str(), NULL, 10);
int height = strtol((parser.GetFlag("h")).c_str(), NULL, 10); int height = strtol((parser.GetFlag("h")).c_str(), NULL, 10);
int framerate = strtol((parser.GetFlag("f")).c_str(), NULL, 10); int framerate = strtol((parser.GetFlag("f")).c_str(), NULL, 10);

View File

@ -16,19 +16,16 @@
'target_name': 'test_support', 'target_name': 'test_support',
'type': 'static_library', 'type': 'static_library',
'include_dirs': [ 'include_dirs': [
# TODO(kjellander): Remove this by making all includes use full paths.
'.', '.',
], ],
'direct_dependent_settings': {
'include_dirs': [
'.', # Some includes are hierarchical
],
},
'dependencies': [ 'dependencies': [
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gmock.gyp:gmock',
], ],
'all_dependent_settings': { 'all_dependent_settings': {
'include_dirs': [ 'include_dirs': [
# TODO(kjellander): Remove this by making all includes use full paths.
'.', '.',
], ],
}, },

View File

@ -12,7 +12,7 @@
#define WEBRTC_TEST_TESTSUPPORT_GTEST_PROD_UTIL_H_ #define WEBRTC_TEST_TESTSUPPORT_GTEST_PROD_UTIL_H_
#pragma once #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. // This file is a plain copy of Chromium's base/gtest_prod_util.h.
// //

View File

@ -107,7 +107,7 @@ int CalculateMetrics(VideoMetricsType video_metrics_type,
int frame_number = 0; int frame_number = 0;
// Read reference and test frames. // 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 ref_frame;
I420VideoFrame test_frame; I420VideoFrame test_frame;
scoped_array<uint8_t> ref_buffer(new uint8_t[frame_length]); scoped_array<uint8_t> ref_buffer(new uint8_t[frame_length]);
@ -118,8 +118,8 @@ int CalculateMetrics(VideoMetricsType video_metrics_type,
ref_frame.CreateEmptyFrame(width, height, width, half_width, half_width); ref_frame.CreateEmptyFrame(width, height, width, half_width, half_width);
test_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); size_t 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 test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp);
while (ref_bytes == frame_length && test_bytes == frame_length) { while (ref_bytes == frame_length && test_bytes == frame_length) {
// Converting from buffer to plane representation. // Converting from buffer to plane representation.
ConvertToI420(kI420, ref_buffer.get(), 0, 0, width, height, 0, ConvertToI420(kI420, ref_buffer.get(), 0, 0, width, height, 0,

View File

@ -20,6 +20,8 @@
namespace webrtc { namespace webrtc {
namespace test { namespace test {
using std::string;
int GetI420FrameSize(int width, int height) { int GetI420FrameSize(int width, int height) {
int half_width = (width + 1) >> 1; int half_width = (width + 1) >> 1;
int half_height = (height + 1) >> 1; int half_height = (height + 1) >> 1;
@ -32,14 +34,14 @@ int GetI420FrameSize(int width, int height) {
} }
int ExtractFrameSequenceNumber(std::string line) { int ExtractFrameSequenceNumber(std::string line) {
int space_position = line.find(' '); size_t space_position = line.find(' ');
if (space_position == -1) { if (space_position == string::npos) {
return -1; return -1;
} }
std::string frame = line.substr(0, space_position); std::string frame = line.substr(0, space_position);
int underscore_position = frame.find('_'); size_t underscore_position = frame.find('_');
if (underscore_position == -1) { if (underscore_position == string::npos) {
return -1; return -1;
} }
std::string frame_number = frame.substr(underscore_position + 1); std::string frame_number = frame.substr(underscore_position + 1);
@ -48,8 +50,8 @@ int ExtractFrameSequenceNumber(std::string line) {
} }
int ExtractDecodedFrameNumber(std::string line) { int ExtractDecodedFrameNumber(std::string line) {
int space_position = line.find(' '); size_t space_position = line.find(' ');
if (space_position == -1) { if (space_position == string::npos) {
return -1; return -1;
} }
std::string decoded_number = line.substr(space_position + 1); std::string decoded_number = line.substr(space_position + 1);
@ -58,8 +60,8 @@ int ExtractDecodedFrameNumber(std::string line) {
} }
bool IsThereBarcodeError(std::string line) { bool IsThereBarcodeError(std::string line) {
int barcode_error_position = line.find("Barcode error"); size_t barcode_error_position = line.find("Barcode error");
if (barcode_error_position != -1) { if (barcode_error_position != string::npos) {
return true; return true;
} }
return false; return false;

View File

@ -8,43 +8,39 @@
* be found in the AUTHORS file in the root of the source tree. * 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 <cstdio>
#include <cstdlib> #include <cstdlib>
#include <string>
namespace webrtc { namespace webrtc {
namespace test { namespace test {
using std::string;
void CommandLineParser::Init(int argc, char** argv) { void CommandLineParser::Init(int argc, char** argv) {
args_ = std::vector<std::string> (argv + 1, argv + argc); args_ = std::vector<std::string> (argv + 1, argv + argc);
} }
bool CommandLineParser::IsStandaloneFlag(std::string flag) { bool CommandLineParser::IsStandaloneFlag(std::string flag) {
int equal_pos = flag.find("="); return flag.find("=") == string::npos;
if (equal_pos < 0) {
return true;
}
return false;
} }
bool CommandLineParser::IsFlagWellFormed(std::string flag) { bool CommandLineParser::IsFlagWellFormed(std::string flag) {
int dash_pos = flag.find("--"); size_t dash_pos = flag.find("--");
int equal_pos = flag.find("="); size_t equal_pos = flag.find("=");
if (dash_pos != 0) { if (dash_pos != 0) {
fprintf(stderr, "Wrong switch format: %s\n", flag.c_str()); fprintf(stderr, "Wrong switch format: %s\n", flag.c_str());
fprintf(stderr, "Flag doesn't start with --\n"); fprintf(stderr, "Flag doesn't start with --\n");
return false; return false;
} }
size_t flag_length = flag.length() - 1;
int flag_length = flag.length() - 1;
// We use 3 here because we assume that the flags are in the format // 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 // --flag_name=flag_value, thus -- are at positions 0 and 1 and we should have
// at least one symbor for the flag name. // at least one symbol for the flag name.
if (equal_pos >= 0 && (equal_pos < 3 || equal_pos == flag_length)) { if (equal_pos > 0 && (equal_pos < 3 || equal_pos == flag_length)) {
fprintf(stderr, "Wrong switch format: %s\n", flag.c_str()); fprintf(stderr, "Wrong switch format: %s\n", flag.c_str());
fprintf(stderr, "Wrong placement of =\n"); fprintf(stderr, "Wrong placement of =\n");
return false; return false;
@ -53,10 +49,9 @@ bool CommandLineParser::IsFlagWellFormed(std::string flag) {
} }
std::string CommandLineParser::GetCommandLineFlagName(std::string flag) { std::string CommandLineParser::GetCommandLineFlagName(std::string flag) {
int dash_pos = flag.find("--"); size_t dash_pos = flag.find("--");
int equal_pos = flag.find("="); size_t equal_pos = flag.find("=");
if (equal_pos == string::npos) {
if (equal_pos < 0) {
return flag.substr(dash_pos + 2); return flag.substr(dash_pos + 2);
} else { } else {
return flag.substr(dash_pos + 2, equal_pos - 2); return flag.substr(dash_pos + 2, equal_pos - 2);
@ -64,10 +59,13 @@ std::string CommandLineParser::GetCommandLineFlagName(std::string flag) {
} }
std::string CommandLineParser::GetCommandLineFlagValue(std::string flag) { std::string CommandLineParser::GetCommandLineFlagValue(std::string flag) {
int equal_pos = flag.find("="); size_t equal_pos = flag.find("=");
if (equal_pos == string::npos) {
return "";
} else {
return flag.substr(equal_pos + 1); return flag.substr(equal_pos + 1);
} }
}
void CommandLineParser::PrintEnteredFlags() { void CommandLineParser::PrintEnteredFlags() {
std::map<std::string, std::string>::iterator flag_iter; std::map<std::string, std::string>::iterator flag_iter;
@ -112,14 +110,15 @@ void CommandLineParser::PrintUsageMessage() {
fprintf(stdout, "%s", usage_message_.c_str()); fprintf(stdout, "%s", usage_message_.c_str());
} }
void CommandLineParser::SetFlag(std::string flag_name, std::string flag_value) { void CommandLineParser::SetFlag(std::string flag_name,
flags_[flag_name] = flag_value; std::string default_flag_value) {
flags_[flag_name] = default_flag_value;
} }
std::string CommandLineParser::GetFlag(std::string flag_name) { std::string CommandLineParser::GetFlag(std::string flag_name) {
std::map<std::string, std::string>::iterator flag_iter; std::map<std::string, std::string>::iterator flag_iter;
flag_iter = flags_.find(flag_name); flag_iter = flags_.find(flag_name);
// If no such file. // If no such flag.
if (flag_iter == flags_.end()) { if (flag_iter == flags_.end()) {
return ""; return "";
} }

View File

@ -15,9 +15,19 @@
#include <map> #include <map>
#include <vector> #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 // 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 // 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. // 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 webrtc {
namespace test { namespace test {
@ -44,9 +54,13 @@ class CommandLineParser {
void PrintUsageMessage(); void PrintUsageMessage();
// Set a flag into the map of flag names/values. // 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); std::string GetFlag(std::string flag_name);
private: private:
@ -61,14 +75,23 @@ class CommandLineParser {
// understand e.g. --standalone (in contrast to --non_standalone=1). // understand e.g. --standalone (in contrast to --non_standalone=1).
bool IsStandaloneFlag(std::string flag); 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); 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); 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); 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 } // namespace test

View File

@ -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

View File

@ -14,14 +14,6 @@
{ {
'target_name': 'command_line_parser', 'target_name': 'command_line_parser',
'type': 'static_library', 'type': 'static_library',
'include_dirs': [
'.',
],
'direct_dependent_settings': {
'include_dirs': [
'.',
],
},
'sources': [ 'sources': [
'simple_command_line_parser.h', 'simple_command_line_parser.h',
'simple_command_line_parser.cc', 'simple_command_line_parser.cc',
@ -114,11 +106,13 @@
'target_name': 'tools_unittests', 'target_name': 'tools_unittests',
'type': 'executable', 'type': 'executable',
'dependencies': [ 'dependencies': [
'command_line_parser',
'frame_editing_lib', 'frame_editing_lib',
'<(webrtc_root)/test/test.gyp:test_support_main', '<(webrtc_root)/test/test.gyp:test_support_main',
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',
], ],
'sources': [ 'sources': [
'simple_command_line_parser_unittest.cc',
'frame_editing/frame_editing_unittest.cc', 'frame_editing/frame_editing_unittest.cc',
], ],
}, # tools_unittests }, # tools_unittests