1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "crazy_linker_thread.h" 6 7 #include <minitest/minitest.h> 8 9 namespace crazy { 10 11 TEST(Thread, GetThreadData) { 12 ThreadData* data = GetThreadData(); 13 TEST_TEXT << "Checking first GetThreadData() call"; 14 EXPECT_TRUE(data); 15 EXPECT_EQ(data, GetThreadData()); 16 EXPECT_EQ(data, GetThreadDataFast()); 17 } 18 19 TEST(Thread, GetErrorEmpty) { 20 ThreadData* data = GetThreadData(); 21 const char* error = data->GetError(); 22 EXPECT_TRUE(error); 23 EXPECT_STREQ("", error); 24 } 25 26 TEST(Thread, SetError) { 27 ThreadData* data = GetThreadData(); 28 data->SetError("Hello"); 29 data->SetError("World"); 30 EXPECT_STREQ("World", data->GetError()); 31 } 32 33 TEST(Thread, SetErrorNull) { 34 ThreadData* data = GetThreadData(); 35 data->SetError("Hello"); 36 data->SetError(NULL); 37 EXPECT_STREQ("", data->GetError()); 38 } 39 40 TEST(Thread, GetError) { 41 ThreadData* data = GetThreadData(); 42 data->SetError("Hello"); 43 44 const char* error = data->GetError(); 45 EXPECT_STREQ("Hello", error); 46 47 error = data->GetError(); 48 EXPECT_STREQ("Hello", error); 49 } 50 51 TEST(Thread, SwapErrorBuffers) { 52 ThreadData* data = GetThreadData(); 53 data->SetError("Hello"); 54 EXPECT_STREQ("Hello", data->GetError()); 55 56 data->SwapErrorBuffers(); 57 EXPECT_STREQ("", data->GetError()); 58 59 data->SetError("World"); 60 EXPECT_STREQ("World", data->GetError()); 61 62 data->SwapErrorBuffers(); 63 EXPECT_STREQ("", data->GetError()); 64 } 65 66 TEST(Thread, AppendErrorTwice) { 67 ThreadData* data = GetThreadData(); 68 data->SetError(NULL); 69 data->AppendError("Hello"); 70 EXPECT_STREQ("Hello", data->GetError()); 71 72 data->AppendError(" World"); 73 EXPECT_STREQ("Hello World", data->GetError()); 74 } 75 76 TEST(Thread, AppendErrorFull) { 77 const size_t kMaxCount = 1000; 78 ThreadData* data = GetThreadData(); 79 data->SetError(NULL); 80 81 for (size_t n = 0; n < kMaxCount; ++n) 82 data->AppendError("0123456789"); 83 84 const char* error = data->GetError(); 85 size_t error_len = strlen(error); 86 87 EXPECT_GT(0, error_len); 88 EXPECT_LT(kMaxCount * 10, error_len); 89 90 for (size_t n = 0; n < error_len; ++n) { 91 TEST_TEXT << "Checking error[" << n << "]"; 92 EXPECT_EQ('0' + (n % 10), error[n]); 93 } 94 } 95 96 TEST(Thread, AppendErrorNull) { 97 ThreadData* data = GetThreadData(); 98 data->SetError("Hello"); 99 data->AppendError(NULL); 100 data->AppendError(" World"); 101 EXPECT_STREQ("Hello World", data->GetError()); 102 } 103 104 TEST(Thread, SetLinkerErrorString) { 105 ThreadData* data = GetThreadData(); 106 107 SetLinkerErrorString("Hello World"); 108 EXPECT_STREQ("Hello World", data->GetError()); 109 110 SetLinkerErrorString(NULL); 111 EXPECT_STREQ("", data->GetError()); 112 } 113 114 TEST(Thread, SetLinkerError) { 115 ThreadData* data = GetThreadData(); 116 117 SetLinkerError("%s %s!", "Hi", "Captain"); 118 EXPECT_STREQ("Hi Captain!", data->GetError()); 119 120 SetLinkerError("Woosh"); 121 EXPECT_STREQ("Woosh", data->GetError()); 122 } 123 124 } // namespace crazy 125