00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "gmock/internal/gmock-internal-utils.h"
00037 #include <stdlib.h>
00038 #include <map>
00039 #include <string>
00040 #include <sstream>
00041 #include <vector>
00042 #include "gmock/gmock.h"
00043 #include "gmock/internal/gmock-port.h"
00044 #include "gtest/gtest.h"
00045 #include "gtest/gtest-spi.h"
00046
00047 #if GTEST_OS_CYGWIN
00048 # include <sys/types.h>
00049 #endif
00050
00051 class ProtocolMessage;
00052
00053 namespace proto2 {
00054 class Message;
00055 }
00056
00057 namespace testing {
00058 namespace internal {
00059
00060 namespace {
00061
00062 using ::std::tr1::make_tuple;
00063 using ::std::tr1::tuple;
00064
00065 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
00066 EXPECT_EQ("", ConvertIdentifierNameToWords(""));
00067 EXPECT_EQ("", ConvertIdentifierNameToWords("_"));
00068 EXPECT_EQ("", ConvertIdentifierNameToWords("__"));
00069 }
00070
00071 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
00072 EXPECT_EQ("1", ConvertIdentifierNameToWords("_1"));
00073 EXPECT_EQ("2", ConvertIdentifierNameToWords("2_"));
00074 EXPECT_EQ("34", ConvertIdentifierNameToWords("_34_"));
00075 EXPECT_EQ("34 56", ConvertIdentifierNameToWords("_34_56"));
00076 }
00077
00078 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
00079 EXPECT_EQ("a big word", ConvertIdentifierNameToWords("ABigWord"));
00080 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("FooBar"));
00081 EXPECT_EQ("foo", ConvertIdentifierNameToWords("Foo_"));
00082 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_Foo_Bar_"));
00083 EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_Foo__And_Bar"));
00084 }
00085
00086 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
00087 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("foo_bar"));
00088 EXPECT_EQ("foo", ConvertIdentifierNameToWords("_foo_"));
00089 EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_foo_bar_"));
00090 EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_foo__and_bar"));
00091 }
00092
00093 TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
00094 EXPECT_EQ("foo bar 123", ConvertIdentifierNameToWords("Foo_bar123"));
00095 EXPECT_EQ("chapter 11 section 1",
00096 ConvertIdentifierNameToWords("_Chapter11Section_1_"));
00097 }
00098
00099 TEST(PointeeOfTest, WorksForSmartPointers) {
00100 CompileAssertTypesEqual<const char,
00101 PointeeOf<internal::linked_ptr<const char> >::type>();
00102 }
00103
00104 TEST(PointeeOfTest, WorksForRawPointers) {
00105 CompileAssertTypesEqual<int, PointeeOf<int*>::type>();
00106 CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>();
00107 CompileAssertTypesEqual<void, PointeeOf<void*>::type>();
00108 }
00109
00110 TEST(GetRawPointerTest, WorksForSmartPointers) {
00111 const char* const raw_p4 = new const char('a');
00112 const internal::linked_ptr<const char> p4(raw_p4);
00113 EXPECT_EQ(raw_p4, GetRawPointer(p4));
00114 }
00115
00116 TEST(GetRawPointerTest, WorksForRawPointers) {
00117 int* p = NULL;
00118
00119 EXPECT_TRUE(NULL == GetRawPointer(p));
00120 int n = 1;
00121 EXPECT_EQ(&n, GetRawPointer(&n));
00122 }
00123
00124
00125
00126 class Base {};
00127 class Derived : public Base {};
00128
00129 TEST(KindOfTest, Bool) {
00130 EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool));
00131 }
00132
00133 TEST(KindOfTest, Integer) {
00134 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char));
00135 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char));
00136 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char));
00137 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short));
00138 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short));
00139 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int));
00140 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int));
00141 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long));
00142 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long));
00143 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t));
00144 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(Int64));
00145 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(UInt64));
00146 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t));
00147 #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
00148
00149 EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t));
00150 #endif
00151 }
00152
00153 TEST(KindOfTest, FloatingPoint) {
00154 EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float));
00155 EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double));
00156 EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(long double));
00157 }
00158
00159 TEST(KindOfTest, Other) {
00160 EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*));
00161 EXPECT_EQ(kOther, GMOCK_KIND_OF_(char**));
00162 EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base));
00163 }
00164
00165
00166
00167 TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
00168 EXPECT_TRUE((LosslessArithmeticConvertible<bool, bool>::value));
00169 }
00170
00171 TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
00172 EXPECT_TRUE((LosslessArithmeticConvertible<bool, char>::value));
00173 EXPECT_TRUE((LosslessArithmeticConvertible<bool, int>::value));
00174 EXPECT_TRUE(
00175 (LosslessArithmeticConvertible<bool, unsigned long>::value));
00176 }
00177
00178 TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
00179 EXPECT_TRUE((LosslessArithmeticConvertible<bool, float>::value));
00180 EXPECT_TRUE((LosslessArithmeticConvertible<bool, double>::value));
00181 }
00182
00183 TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
00184 EXPECT_FALSE((LosslessArithmeticConvertible<unsigned char, bool>::value));
00185 EXPECT_FALSE((LosslessArithmeticConvertible<int, bool>::value));
00186 }
00187
00188 TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
00189
00190 EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
00191
00192
00193 EXPECT_TRUE(
00194 (LosslessArithmeticConvertible<unsigned short, UInt64>::value));
00195
00196
00197 EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value));
00198 EXPECT_FALSE((LosslessArithmeticConvertible<
00199 signed char, unsigned int>::value));
00200
00201
00202 EXPECT_TRUE((LosslessArithmeticConvertible<
00203 unsigned char, unsigned char>::value));
00204 EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value));
00205 EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value));
00206 EXPECT_TRUE((LosslessArithmeticConvertible<
00207 unsigned long, unsigned long>::value));
00208
00209
00210 EXPECT_FALSE((LosslessArithmeticConvertible<
00211 unsigned char, signed char>::value));
00212 EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
00213 EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value));
00214
00215
00216 EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value));
00217 EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value));
00218 EXPECT_FALSE((LosslessArithmeticConvertible<Int64, unsigned int>::value));
00219 }
00220
00221 TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
00222
00223
00224 EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value));
00225 EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value));
00226 EXPECT_FALSE((LosslessArithmeticConvertible<
00227 short, long double>::value));
00228 }
00229
00230 TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
00231 EXPECT_FALSE((LosslessArithmeticConvertible<float, bool>::value));
00232 EXPECT_FALSE((LosslessArithmeticConvertible<double, bool>::value));
00233 }
00234
00235 TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
00236 EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value));
00237 EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value));
00238 EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value));
00239 }
00240
00241 TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
00242
00243 EXPECT_TRUE((LosslessArithmeticConvertible<float, double>::value));
00244 EXPECT_TRUE((LosslessArithmeticConvertible<float, long double>::value));
00245 EXPECT_TRUE((LosslessArithmeticConvertible<double, long double>::value));
00246
00247
00248 EXPECT_TRUE((LosslessArithmeticConvertible<float, float>::value));
00249 EXPECT_TRUE((LosslessArithmeticConvertible<double, double>::value));
00250
00251
00252 EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value));
00253 if (sizeof(double) == sizeof(long double)) {
00254
00255
00256 EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value));
00257 } else {
00258 EXPECT_FALSE((LosslessArithmeticConvertible<long double, double>::value));
00259 }
00260 }
00261
00262
00263
00264 TEST(TupleMatchesTest, WorksForSize0) {
00265 tuple<> matchers;
00266 tuple<> values;
00267
00268 EXPECT_TRUE(TupleMatches(matchers, values));
00269 }
00270
00271 TEST(TupleMatchesTest, WorksForSize1) {
00272 tuple<Matcher<int> > matchers(Eq(1));
00273 tuple<int> values1(1),
00274 values2(2);
00275
00276 EXPECT_TRUE(TupleMatches(matchers, values1));
00277 EXPECT_FALSE(TupleMatches(matchers, values2));
00278 }
00279
00280 TEST(TupleMatchesTest, WorksForSize2) {
00281 tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
00282 tuple<int, char> values1(1, 'a'),
00283 values2(1, 'b'),
00284 values3(2, 'a'),
00285 values4(2, 'b');
00286
00287 EXPECT_TRUE(TupleMatches(matchers, values1));
00288 EXPECT_FALSE(TupleMatches(matchers, values2));
00289 EXPECT_FALSE(TupleMatches(matchers, values3));
00290 EXPECT_FALSE(TupleMatches(matchers, values4));
00291 }
00292
00293 TEST(TupleMatchesTest, WorksForSize5) {
00294 tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>,
00295 Matcher<string> >
00296 matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
00297 tuple<int, char, bool, long, string>
00298 values1(1, 'a', true, 2L, "hi"),
00299 values2(1, 'a', true, 2L, "hello"),
00300 values3(2, 'a', true, 2L, "hi");
00301
00302 EXPECT_TRUE(TupleMatches(matchers, values1));
00303 EXPECT_FALSE(TupleMatches(matchers, values2));
00304 EXPECT_FALSE(TupleMatches(matchers, values3));
00305 }
00306
00307
00308 TEST(AssertTest, SucceedsOnTrue) {
00309 Assert(true, __FILE__, __LINE__, "This should succeed.");
00310 Assert(true, __FILE__, __LINE__);
00311 }
00312
00313
00314 TEST(AssertTest, FailsFatallyOnFalse) {
00315 EXPECT_DEATH_IF_SUPPORTED({
00316 Assert(false, __FILE__, __LINE__, "This should fail.");
00317 }, "");
00318
00319 EXPECT_DEATH_IF_SUPPORTED({
00320 Assert(false, __FILE__, __LINE__);
00321 }, "");
00322 }
00323
00324
00325 TEST(ExpectTest, SucceedsOnTrue) {
00326 Expect(true, __FILE__, __LINE__, "This should succeed.");
00327 Expect(true, __FILE__, __LINE__);
00328 }
00329
00330
00331 TEST(ExpectTest, FailsNonfatallyOnFalse) {
00332 EXPECT_NONFATAL_FAILURE({
00333 Expect(false, __FILE__, __LINE__, "This should fail.");
00334 }, "This should fail");
00335
00336 EXPECT_NONFATAL_FAILURE({
00337 Expect(false, __FILE__, __LINE__);
00338 }, "Expectation failed");
00339 }
00340
00341
00342
00343 class LogIsVisibleTest : public ::testing::Test {
00344 protected:
00345 virtual void SetUp() {
00346 original_verbose_ = GMOCK_FLAG(verbose);
00347 }
00348
00349 virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; }
00350
00351 string original_verbose_;
00352 };
00353
00354 TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
00355 GMOCK_FLAG(verbose) = kInfoVerbosity;
00356 EXPECT_TRUE(LogIsVisible(kInfo));
00357 EXPECT_TRUE(LogIsVisible(kWarning));
00358 }
00359
00360 TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
00361 GMOCK_FLAG(verbose) = kErrorVerbosity;
00362 EXPECT_FALSE(LogIsVisible(kInfo));
00363 EXPECT_FALSE(LogIsVisible(kWarning));
00364 }
00365
00366 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
00367 GMOCK_FLAG(verbose) = kWarningVerbosity;
00368 EXPECT_FALSE(LogIsVisible(kInfo));
00369 EXPECT_TRUE(LogIsVisible(kWarning));
00370 }
00371
00372 #if GTEST_HAS_STREAM_REDIRECTION
00373
00374
00375
00376
00377
00378 void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
00379 bool should_print) {
00380 const string old_flag = GMOCK_FLAG(verbose);
00381 GMOCK_FLAG(verbose) = verbosity;
00382 CaptureStdout();
00383 Log(severity, "Test log.\n", 0);
00384 if (should_print) {
00385 EXPECT_THAT(GetCapturedStdout().c_str(),
00386 ContainsRegex(
00387 severity == kWarning ?
00388 "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
00389 "^\nTest log\\.\nStack trace:\n"));
00390 } else {
00391 EXPECT_STREQ("", GetCapturedStdout().c_str());
00392 }
00393 GMOCK_FLAG(verbose) = old_flag;
00394 }
00395
00396
00397
00398 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
00399 const string saved_flag = GMOCK_FLAG(verbose);
00400 GMOCK_FLAG(verbose) = kInfoVerbosity;
00401 CaptureStdout();
00402 Log(kInfo, "Test log.\n", -1);
00403 EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
00404 GMOCK_FLAG(verbose) = saved_flag;
00405 }
00406
00407
00408
00409 TEST(LogTest, NoSkippingStackFrameInOptMode) {
00410 CaptureStdout();
00411 Log(kWarning, "Test log.\n", 100);
00412 const string log = GetCapturedStdout();
00413
00414 # if defined(NDEBUG) && GTEST_GOOGLE3_MODE_
00415
00416
00417 EXPECT_THAT(log, ContainsRegex("\nGMOCK WARNING:\n"
00418 "Test log\\.\n"
00419 "Stack trace:\n"
00420 ".+"));
00421 # else
00422
00423
00424 EXPECT_STREQ("\nGMOCK WARNING:\n"
00425 "Test log.\n"
00426 "Stack trace:\n", log.c_str());
00427 # endif
00428 }
00429
00430
00431
00432 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
00433 TestLogWithSeverity(kInfoVerbosity, kInfo, true);
00434 TestLogWithSeverity(kInfoVerbosity, kWarning, true);
00435 }
00436
00437
00438
00439 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
00440 TestLogWithSeverity(kWarningVerbosity, kInfo, false);
00441 TestLogWithSeverity(kWarningVerbosity, kWarning, true);
00442 }
00443
00444
00445
00446 TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
00447 TestLogWithSeverity(kErrorVerbosity, kInfo, false);
00448 TestLogWithSeverity(kErrorVerbosity, kWarning, false);
00449 }
00450
00451
00452
00453 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
00454 TestLogWithSeverity("invalid", kInfo, false);
00455 TestLogWithSeverity("invalid", kWarning, true);
00456 }
00457
00458 #endif // GTEST_HAS_STREAM_REDIRECTION
00459
00460 TEST(TypeTraitsTest, true_type) {
00461 EXPECT_TRUE(true_type::value);
00462 }
00463
00464 TEST(TypeTraitsTest, false_type) {
00465 EXPECT_FALSE(false_type::value);
00466 }
00467
00468 TEST(TypeTraitsTest, is_reference) {
00469 EXPECT_FALSE(is_reference<int>::value);
00470 EXPECT_FALSE(is_reference<char*>::value);
00471 EXPECT_TRUE(is_reference<const int&>::value);
00472 }
00473
00474 TEST(TypeTraitsTest, is_pointer) {
00475 EXPECT_FALSE(is_pointer<int>::value);
00476 EXPECT_FALSE(is_pointer<char&>::value);
00477 EXPECT_TRUE(is_pointer<const int*>::value);
00478 }
00479
00480 TEST(TypeTraitsTest, type_equals) {
00481 EXPECT_FALSE((type_equals<int, const int>::value));
00482 EXPECT_FALSE((type_equals<int, int&>::value));
00483 EXPECT_FALSE((type_equals<int, double>::value));
00484 EXPECT_TRUE((type_equals<char, char>::value));
00485 }
00486
00487 TEST(TypeTraitsTest, remove_reference) {
00488 EXPECT_TRUE((type_equals<char, remove_reference<char&>::type>::value));
00489 EXPECT_TRUE((type_equals<const int,
00490 remove_reference<const int&>::type>::value));
00491 EXPECT_TRUE((type_equals<int, remove_reference<int>::type>::value));
00492 EXPECT_TRUE((type_equals<double*, remove_reference<double*>::type>::value));
00493 }
00494
00495 #if GTEST_HAS_STREAM_REDIRECTION
00496
00497
00498
00499 std::string GrabOutput(void(*logger)(), const char* verbosity) {
00500 const string saved_flag = GMOCK_FLAG(verbose);
00501 GMOCK_FLAG(verbose) = verbosity;
00502 CaptureStdout();
00503 logger();
00504 GMOCK_FLAG(verbose) = saved_flag;
00505 return GetCapturedStdout();
00506 }
00507
00508 class DummyMock {
00509 public:
00510 MOCK_METHOD0(TestMethod, void());
00511 MOCK_METHOD1(TestMethodArg, void(int dummy));
00512 };
00513
00514 void ExpectCallLogger() {
00515 DummyMock mock;
00516 EXPECT_CALL(mock, TestMethod());
00517 mock.TestMethod();
00518 };
00519
00520
00521 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
00522 EXPECT_THAT(std::string(GrabOutput(ExpectCallLogger, kInfoVerbosity)),
00523 HasSubstr("EXPECT_CALL(mock, TestMethod())"));
00524 }
00525
00526
00527
00528 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
00529 EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str());
00530 }
00531
00532
00533
00534 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
00535 EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str());
00536 }
00537
00538 void OnCallLogger() {
00539 DummyMock mock;
00540 ON_CALL(mock, TestMethod());
00541 };
00542
00543
00544 TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
00545 EXPECT_THAT(std::string(GrabOutput(OnCallLogger, kInfoVerbosity)),
00546 HasSubstr("ON_CALL(mock, TestMethod())"));
00547 }
00548
00549
00550
00551 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
00552 EXPECT_STREQ("", GrabOutput(OnCallLogger, kWarningVerbosity).c_str());
00553 }
00554
00555
00556
00557 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
00558 EXPECT_STREQ("", GrabOutput(OnCallLogger, kErrorVerbosity).c_str());
00559 }
00560
00561 void OnCallAnyArgumentLogger() {
00562 DummyMock mock;
00563 ON_CALL(mock, TestMethodArg(_));
00564 }
00565
00566
00567 TEST(OnCallTest, LogsAnythingArgument) {
00568 EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)),
00569 HasSubstr("ON_CALL(mock, TestMethodArg(_)"));
00570 }
00571
00572 #endif // GTEST_HAS_STREAM_REDIRECTION
00573
00574
00575
00576 TEST(StlContainerViewTest, WorksForStlContainer) {
00577 StaticAssertTypeEq<std::vector<int>,
00578 StlContainerView<std::vector<int> >::type>();
00579 StaticAssertTypeEq<const std::vector<double>&,
00580 StlContainerView<std::vector<double> >::const_reference>();
00581
00582 typedef std::vector<char> Chars;
00583 Chars v1;
00584 const Chars& v2(StlContainerView<Chars>::ConstReference(v1));
00585 EXPECT_EQ(&v1, &v2);
00586
00587 v1.push_back('a');
00588 Chars v3 = StlContainerView<Chars>::Copy(v1);
00589 EXPECT_THAT(v3, Eq(v3));
00590 }
00591
00592 TEST(StlContainerViewTest, WorksForStaticNativeArray) {
00593 StaticAssertTypeEq<NativeArray<int>,
00594 StlContainerView<int[3]>::type>();
00595 StaticAssertTypeEq<NativeArray<double>,
00596 StlContainerView<const double[4]>::type>();
00597 StaticAssertTypeEq<NativeArray<char[3]>,
00598 StlContainerView<const char[2][3]>::type>();
00599
00600 StaticAssertTypeEq<const NativeArray<int>,
00601 StlContainerView<int[2]>::const_reference>();
00602
00603 int a1[3] = { 0, 1, 2 };
00604 NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
00605 EXPECT_EQ(3U, a2.size());
00606 EXPECT_EQ(a1, a2.begin());
00607
00608 const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1);
00609 ASSERT_EQ(3U, a3.size());
00610 EXPECT_EQ(0, a3.begin()[0]);
00611 EXPECT_EQ(1, a3.begin()[1]);
00612 EXPECT_EQ(2, a3.begin()[2]);
00613
00614
00615 a1[0] = 3;
00616 EXPECT_EQ(0, a3.begin()[0]);
00617 }
00618
00619 TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
00620 StaticAssertTypeEq<NativeArray<int>,
00621 StlContainerView<tuple<const int*, size_t> >::type>();
00622 StaticAssertTypeEq<NativeArray<double>,
00623 StlContainerView<tuple<linked_ptr<double>, int> >::type>();
00624
00625 StaticAssertTypeEq<const NativeArray<int>,
00626 StlContainerView<tuple<const int*, int> >::const_reference>();
00627
00628 int a1[3] = { 0, 1, 2 };
00629 const int* const p1 = a1;
00630 NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
00631 ConstReference(make_tuple(p1, 3));
00632 EXPECT_EQ(3U, a2.size());
00633 EXPECT_EQ(a1, a2.begin());
00634
00635 const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
00636 Copy(make_tuple(static_cast<int*>(a1), 3));
00637 ASSERT_EQ(3U, a3.size());
00638 EXPECT_EQ(0, a3.begin()[0]);
00639 EXPECT_EQ(1, a3.begin()[1]);
00640 EXPECT_EQ(2, a3.begin()[2]);
00641
00642
00643 a1[0] = 3;
00644 EXPECT_EQ(0, a3.begin()[0]);
00645 }
00646
00647 }
00648 }
00649 }