Limit use of default namespace in tests and utility programs (#71). r=bryner

- main is now the only thing you'll find in the default namespace.
   Everything else has been moved into an unnamed namespace.

http://groups.google.com/group/airbag-dev/browse_thread/thread/14130a0284a0307f


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@63 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
mmentovai 2006-11-09 17:04:56 +00:00
parent 76f052f8fb
commit 8647dde8cc
9 changed files with 78 additions and 29 deletions

View file

@ -47,6 +47,8 @@
#define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2)) #define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2))
namespace {
using google_airbag::AddressMap; using google_airbag::AddressMap;
using google_airbag::linked_ptr; using google_airbag::linked_ptr;
@ -185,6 +187,8 @@ static bool RunTests() {
return true; return true;
} }
} // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View file

@ -45,6 +45,9 @@
#define ASSERT_FALSE(condition) ASSERT_TRUE(!(condition)) #define ASSERT_FALSE(condition) ASSERT_TRUE(!(condition))
namespace {
using google_airbag::ContainedRangeMap; using google_airbag::ContainedRangeMap;
@ -248,6 +251,9 @@ static bool RunTests() {
} }
} // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View file

@ -36,18 +36,22 @@
#include "google_airbag/processor/minidump.h" #include "google_airbag/processor/minidump.h"
using namespace google_airbag; namespace {
int main(int argc, char **argv) { using google_airbag::Minidump;
if (argc != 2) { using google_airbag::MinidumpThreadList;
fprintf(stderr, "usage: %s <file>\n", argv[0]); using google_airbag::MinidumpModuleList;
return 1; using google_airbag::MinidumpMemoryList;
} using google_airbag::MinidumpException;
using google_airbag::MinidumpSystemInfo;
using google_airbag::MinidumpMiscInfo;
using google_airbag::MinidumpAirbagInfo;
Minidump minidump(argv[1]); static bool PrintMinidumpDump(const char *minidump_file) {
Minidump minidump(minidump_file);
if (!minidump.Read()) { if (!minidump.Read()) {
printf("minidump.Read() failed\n"); fprintf(stderr, "minidump.Read() failed\n");
return 1; return false;
} }
minidump.Print(); minidump.Print();
@ -109,6 +113,16 @@ int main(int argc, char **argv) {
airbag_info->Print(); airbag_info->Print();
} }
// Use return instead of exit to allow destructors to run. return errors == 0;
return errors == 0 ? 0 : 1; }
} // namespace
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "usage: %s <file>\n", argv[0]);
return 1;
}
return PrintMinidumpDump(argv[1]) ? 0 : 1;
} }

View file

@ -39,11 +39,15 @@
#include "google_airbag/processor/symbol_supplier.h" #include "google_airbag/processor/symbol_supplier.h"
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
namespace {
using std::string; using std::string;
using google_airbag::CallStack; using google_airbag::CallStack;
using google_airbag::MinidumpModule;
using google_airbag::MinidumpProcessor; using google_airbag::MinidumpProcessor;
using google_airbag::ProcessState; using google_airbag::ProcessState;
using google_airbag::scoped_ptr; using google_airbag::scoped_ptr;
using google_airbag::SymbolSupplier;
#define ASSERT_TRUE(cond) \ #define ASSERT_TRUE(cond) \
if (!(cond)) { \ if (!(cond)) { \
@ -53,8 +57,6 @@ using google_airbag::scoped_ptr;
#define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2)) #define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2))
namespace google_airbag {
class TestSymbolSupplier : public SymbolSupplier { class TestSymbolSupplier : public SymbolSupplier {
public: public:
virtual string GetSymbolFile(MinidumpModule *module); virtual string GetSymbolFile(MinidumpModule *module);
@ -72,10 +74,6 @@ string TestSymbolSupplier::GetSymbolFile(MinidumpModule *module) {
return ""; return "";
} }
} // namespace google_airbag
using google_airbag::TestSymbolSupplier;
static bool RunTests() { static bool RunTests() {
TestSymbolSupplier supplier; TestSymbolSupplier supplier;
MinidumpProcessor processor(&supplier); MinidumpProcessor processor(&supplier);
@ -129,6 +127,8 @@ static bool RunTests() {
return true; return true;
} }
} // namespace
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (!RunTests()) { if (!RunTests()) {
return 1; return 1;

View file

@ -45,6 +45,8 @@
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
#include "processor/simple_symbol_supplier.h" #include "processor/simple_symbol_supplier.h"
namespace {
using std::string; using std::string;
using google_airbag::CallStack; using google_airbag::CallStack;
using google_airbag::MinidumpModule; using google_airbag::MinidumpModule;
@ -218,6 +220,8 @@ static bool PrintMinidumpProcess(const string &minidump_file,
return true; return true;
} }
} // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc < 2 || argc > 3) { if (argc < 2 || argc > 3) {
fprintf(stderr, "usage: %s <minidump-file> [symbol-path]\n", argv[0]); fprintf(stderr, "usage: %s <minidump-file> [symbol-path]\n", argv[0]);

View file

@ -37,6 +37,8 @@
#define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2)) #define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2))
namespace {
using google_airbag::PathnameStripper; using google_airbag::PathnameStripper;
static bool RunTests() { static bool RunTests() {
@ -73,6 +75,8 @@ static bool RunTests() {
return true; return true;
} }
} // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View file

@ -26,6 +26,9 @@
#include "google_airbag/processor/memory_region.h" #include "google_airbag/processor/memory_region.h"
namespace {
using std::map; using std::map;
using std::string; using std::string;
using google_airbag::MemoryRegion; using google_airbag::MemoryRegion;
@ -84,7 +87,7 @@ struct EvaluateTestSet {
}; };
bool RunTests() { static bool RunTests() {
// The first test set checks the basic operations and failure modes. // The first test set checks the basic operations and failure modes.
PostfixEvaluator<unsigned int>::DictionaryType dictionary_0; PostfixEvaluator<unsigned int>::DictionaryType dictionary_0;
const EvaluateTest evaluate_tests_0[] = { const EvaluateTest evaluate_tests_0[] = {
@ -274,6 +277,9 @@ bool RunTests() {
} }
} // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View file

@ -41,6 +41,9 @@
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
namespace {
using google_airbag::linked_ptr; using google_airbag::linked_ptr;
using google_airbag::scoped_ptr; using google_airbag::scoped_ptr;
using google_airbag::RangeMap; using google_airbag::RangeMap;
@ -99,7 +102,7 @@ struct RangeTestSet {
// StoreTest uses the data in a RangeTest and calls StoreRange on the // StoreTest uses the data in a RangeTest and calls StoreRange on the
// test RangeMap. It returns true if the expected result occurred, and // test RangeMap. It returns true if the expected result occurred, and
// false if something else happened. // false if something else happened.
bool StoreTest(TestMap *range_map, const RangeTest *range_test) { static bool StoreTest(TestMap *range_map, const RangeTest *range_test) {
linked_ptr<CountedObject> object(new CountedObject(range_test->id)); linked_ptr<CountedObject> object(new CountedObject(range_test->id));
bool stored = range_map->StoreRange(range_test->address, bool stored = range_map->StoreRange(range_test->address,
range_test->size, range_test->size,
@ -123,7 +126,7 @@ bool StoreTest(TestMap *range_map, const RangeTest *range_test) {
// map entry at the specified range,) it returns true, otherwise, it returns // map entry at the specified range,) it returns true, otherwise, it returns
// false. RetrieveTest will check the values around the base address and // false. RetrieveTest will check the values around the base address and
// the high address of a range to guard against off-by-one errors. // the high address of a range to guard against off-by-one errors.
bool RetrieveTest(TestMap *range_map, const RangeTest *range_test) { static bool RetrieveTest(TestMap *range_map, const RangeTest *range_test) {
for (unsigned int side = 0; side <= 1; ++side) { for (unsigned int side = 0; side <= 1; ++side) {
// When side == 0, check the low side (base address) of each range. // When side == 0, check the low side (base address) of each range.
// When side == 1, check the high side (base + size) of each range. // When side == 1, check the high side (base + size) of each range.
@ -241,7 +244,7 @@ bool RetrieveTest(TestMap *range_map, const RangeTest *range_test) {
// RunTests runs a series of test sets. // RunTests runs a series of test sets.
bool RunTests() { static bool RunTests() {
// These tests will be run sequentially. The first set of tests exercises // These tests will be run sequentially. The first set of tests exercises
// most functions of RangeTest, and verifies all of the bounds-checking. // most functions of RangeTest, and verifies all of the bounds-checking.
const RangeTest range_tests_0[] = { const RangeTest range_tests_0[] = {
@ -402,6 +405,10 @@ bool RunTests() {
return true; return true;
} }
} // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
return RunTests() ? 0 : 1; return RunTests() ? 0 : 1;
} }

View file

@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h> #include <cstdio>
#include <string> #include <string>
#include "processor/source_line_resolver.h" #include "processor/source_line_resolver.h"
#include "google_airbag/processor/stack_frame.h" #include "google_airbag/processor/stack_frame.h"
@ -35,13 +35,6 @@
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
#include "processor/stack_frame_info.h" #include "processor/stack_frame_info.h"
using std::string;
using google_airbag::linked_ptr;
using google_airbag::scoped_ptr;
using google_airbag::SourceLineResolver;
using google_airbag::StackFrame;
using google_airbag::StackFrameInfo;
#define ASSERT_TRUE(cond) \ #define ASSERT_TRUE(cond) \
if (!(cond)) { \ if (!(cond)) { \
fprintf(stderr, "FAILED: %s at %s:%d\n", #cond, __FILE__, __LINE__); \ fprintf(stderr, "FAILED: %s at %s:%d\n", #cond, __FILE__, __LINE__); \
@ -52,6 +45,15 @@ using google_airbag::StackFrameInfo;
#define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2)) #define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2))
namespace {
using std::string;
using google_airbag::linked_ptr;
using google_airbag::scoped_ptr;
using google_airbag::SourceLineResolver;
using google_airbag::StackFrame;
using google_airbag::StackFrameInfo;
static bool VerifyEmpty(const StackFrame &frame) { static bool VerifyEmpty(const StackFrame &frame) {
ASSERT_TRUE(frame.function_name.empty()); ASSERT_TRUE(frame.function_name.empty());
ASSERT_TRUE(frame.source_file_name.empty()); ASSERT_TRUE(frame.source_file_name.empty());
@ -146,6 +148,8 @@ static bool RunTests() {
return true; return true;
} }
} // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (!RunTests()) { if (!RunTests()) {
return 1; return 1;