本文整理汇总了C++中ASSERT_EQUALS函数的典型用法代码示例。如果您正苦于以下问题:C++ ASSERT_EQUALS函数的具体用法?C++ ASSERT_EQUALS怎么用?C++ ASSERT_EQUALS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ASSERT_EQUALS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert_ValueFuntion_isSymmetrical
void assert_ValueFuntion_isSymmetrical(ValueFunction *vfunc) {
#if STATE_SPACE_DIMENSION != 4
#error "Works only in the four dimensional state space"
#endif
if (vfunc == NULL)
return;
GameStateDomain *domain = vfunc->getDomain();
GridPointIndex *maxIndex = domain->getMaximalGridIndex();
GridPointIndex *cur = new int[STATE_SPACE_DIMENSION];
GridPointIndex *sym = new int[STATE_SPACE_DIMENSION];
for (int i0 = 0; i0 < maxIndex[0] + 1; i0++) {
cur[0] = i0;
for (int i1 = 0; i1 < maxIndex[1] + 1; i1++) {
cur[1] = i1;
for (int i2 = 0; i2 < maxIndex[2] + 1; i2++) {
cur[2] = i2;
for (int i3 = 0; i3 < maxIndex[3] + 1; i3++) {
cur[3] = i3;
/* Now e check all the symmtries of the value function by
* Cristini and Falcone mentioned on page 194 (or 18)
*/
// First build symmetry (20)
for (int i = 0; i < STATE_SPACE_DIMENSION; i++)
sym[i] = maxIndex[i] - cur[i];
ASSERT_EQUALS(vfunc->getValue(cur), vfunc->getValue(sym),
1e-3,
"No Symmetry (20) at %d %d %d %d (%f) != %d %d %d %d (%f)\n",
cur[0], cur[1], cur[2], cur[3], vfunc->getValue(cur), sym[0], sym[1], sym[2], sym[3], vfunc->getValue(sym));
// Next Symmetry (21)
sym[0] = maxIndex[0] - cur[0];
sym[1] = cur[1];
sym[2] = maxIndex[2] - cur[2];
sym[3] = cur[3];
ASSERT_EQUALS(vfunc->getValue(cur), vfunc->getValue(sym),
1e-3,
"No Symmetry (21) at %d %d %d %d (%f) != %d %d %d %d (%f)\n",
cur[0], cur[1], cur[2], cur[3], vfunc->getValue(cur), sym[0], sym[1], sym[2], sym[3], vfunc->getValue(sym));
// Next Symmetry (22)
sym[0] = cur[0];
sym[1] = maxIndex[1] - cur[1];
sym[2] = cur[2];
sym[3] = maxIndex[3] - cur[3];
ASSERT_EQUALS(vfunc->getValue(cur), vfunc->getValue(sym),
1e-3,
"No Symmetry (22) at %d %d %d %d (%f) != %d %d %d %d (%f)\n",
cur[0], cur[1], cur[2], cur[3], vfunc->getValue(cur), sym[0], sym[1], sym[2], sym[3], vfunc->getValue(sym));
}
}
}
}
delete[] cur;
}
示例2: TEST_F
TEST_F(SyncTailTest, MultiSyncApplyGroupsInsertOperationByNamespaceBeforeApplying) {
int seconds = 0;
auto makeOp = [&seconds](const NamespaceString& nss) {
return makeInsertDocumentOplogEntry(
{Timestamp(Seconds(seconds), 0), 1LL}, nss, BSON("_id" << seconds++));
};
NamespaceString nss1("test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_1");
NamespaceString nss2("test." + _agent.getSuiteName() + "_" + _agent.getTestName() + "_2");
auto createOp1 = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss1);
auto createOp2 = makeCreateCollectionOplogEntry({Timestamp(Seconds(seconds++), 0), 1LL}, nss2);
auto insertOp1a = makeOp(nss1);
auto insertOp1b = makeOp(nss1);
auto insertOp2a = makeOp(nss2);
auto insertOp2b = makeOp(nss2);
MultiApplier::Operations operationsApplied;
auto syncApply = [&operationsApplied](OperationContext*, const BSONObj& op, bool) {
operationsApplied.push_back(OplogEntry(op));
return Status::OK();
};
MultiApplier::OperationPtrs ops = {
&createOp1, &createOp2, &insertOp1a, &insertOp2a, &insertOp1b, &insertOp2b};
ASSERT_OK(multiSyncApply_noAbort(_txn.get(), &ops, syncApply));
ASSERT_EQUALS(4U, operationsApplied.size());
ASSERT_EQUALS(createOp1, operationsApplied[0]);
ASSERT_EQUALS(createOp2, operationsApplied[1]);
// Check grouped insert operations in namespace "nss1".
ASSERT_EQUALS(insertOp1a.getOpTime(), operationsApplied[2].getOpTime());
ASSERT_EQUALS(insertOp1a.ns, operationsApplied[2].ns);
ASSERT_EQUALS(BSONType::Array, operationsApplied[2].o.type());
auto group1 = operationsApplied[2].o.Array();
ASSERT_EQUALS(2U, group1.size());
ASSERT_EQUALS(insertOp1a.o.Obj(), group1[0].Obj());
ASSERT_EQUALS(insertOp1b.o.Obj(), group1[1].Obj());
// Check grouped insert operations in namespace "nss2".
ASSERT_EQUALS(insertOp2a.getOpTime(), operationsApplied[3].getOpTime());
ASSERT_EQUALS(insertOp2a.ns, operationsApplied[3].ns);
ASSERT_EQUALS(BSONType::Array, operationsApplied[3].o.type());
auto group2 = operationsApplied[3].o.Array();
ASSERT_EQUALS(2U, group2.size());
ASSERT_EQUALS(insertOp2a.o.Obj(), group2[0].Obj());
ASSERT_EQUALS(insertOp2b.o.Obj(), group2[1].Obj());
}
示例3: INFO_PRINTF1
void CTestAsyncSuplLbsApi::TestObserverLocalL()
//
// Test the use of an MLbsHostSettingsStoreObserver implementation within
// the process that is modifying the settings store.
//
// This test creates two instances of CLbsHostSettingsStore and an observer
// instance for each one. Only the first store instance is used for settings
// modifications. The API specifies that an application will not receive
// notifications for changes it itself has made via the same instance of
// CLbsHostSettingsStore, so only observer 2 should receive notifications.
//
// 1. Create two observers
// 2. Create two store instances and start notifiers
// 3. Create waiter
// 4. Read the initial host settings in from the ini file
// 5. Create a host settings entry using the initial settings
// 6. Retrieve & validate
// 7. Wait for notifier to call LbsHostSettingsUpdated()
// 8. Get new host settings
// 9. Update the previously added entry
// 10. Retrieve and validate
// 11. Wait for notifier to call LbsHostSettingsUpdated()
// 12. Create another settings entry
// 13. Wait for notifier to call LbsHostSettingsUpdated()
// 14. Set second entry as default
// 15. Update second entry
// 16. Wait for notifier to call LbsHostSettingsUpdated()
// 17. Delete first entry
// 18. Wait for notifier to call LbsHostSettingsUpdated()
// 19. Try to update a non-existent entry
// 20. Update a valid entry
// 21. Wait for notifier to call LbsHostSettingsUpdated()
// 22. Try to delete a non-existent entry
// 23. Delete a valid entry
// 24. Wait for notifier to call LbsHostSettingsUpdated()
// 25. Retrieve the extended interface
// 26. Check the version number
//
// Note that for a given observer, the calls to WaitActive() catch only the
// *first* notification since the previous call to that function. Any others
// will be lost since the CenRep notification request is not renewed until
// CLbsHostSettingsNotifier::RunL() gets invoked. This should not matter since
// we expect only one notification per modified settings entry, but it doesn't
// prove that we aren't getting multiple notifications. (TestObserverMultiAppL()
// does not suffer from this limitation.)
//
{
INFO_PRINTF1(_L("CTestAsyncSuplLbsApi::TestObserverLocalL"));
// Create active scheduler
CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
// 1. Create two observers
iObserver1 = CTestLbsHostSettingsStoreObserver::NewL(this);
iObserver2 = CTestLbsHostSettingsStoreObserver::NewL(this);
// 2. Create two store instances with the corresponding observers,
// and start notifiers
iLBSHostStore1 = CLbsHostSettingsStore::NewL(KLbsHostSettingsSuplStoreId, *iObserver1);
iLBSHostStore2 = CLbsHostSettingsStore::NewL(KLbsHostSettingsSuplStoreId, *iObserver2);
// 3. Create waiter. Note: waiter must be created after notifiers are
// started otherwise a panic E32USER-CBase 46 (stray signal) results.
iWaiter = new(ELeave) CActiveWaiter;
// 4. Read the initial host settings in from the ini file
TLbsHostSettingsSupl settings;
ASSERT_EQUALS(KErrNone, CTestSuplUtils::GetHostSettingFromConfig(iConfig, settings, _L("HostSetting_Default")));
// 5. Create a host settings entry using the initial settings
TLbsHostSettingsId newSettingId1;
TInt err = iLBSHostStore1->CreateHostSettings(settings, KLbsHostSettingsTestCreatorId, newSettingId1);
ASSERT_EQUALS(KErrNone, err);
// 6. Retrieve & validate
TLbsHostSettingsSupl settingResult;
err = iLBSHostStore1->GetHostSettings(newSettingId1, settingResult);
ASSERT_EQUALS(err, KErrNone);
ASSERT_TRUE(CTestSuplUtils::AreSettingsEqual(settings, settingResult));
// 7. Wait for notifier to call LbsHostSettingsUpdated()
iWaiter->WaitActive();
ASSERT_EQUALS(iObservedError, KErrNone);
ASSERT_EQUALS(iObservedStoreId, KLbsHostSettingsSuplStoreId);
ASSERT_EQUALS(iObservedSettingsId, newSettingId1);
ASSERT_FALSE(iObserver1Notified);
// 8. Get new host settings
TLbsHostSettingsSupl settings2;
ASSERT_EQUALS(KErrNone, CTestSuplUtils::GetHostSettingFromConfig(iConfig, settings2, _L("HostSetting_Two")));
// 9. Update the previously added entry
err = iLBSHostStore1->UpdateHostSettings(newSettingId1, settings2);
ASSERT_EQUALS(err, KErrNone);
// 10. Retrieve and validate
err = iLBSHostStore1->GetHostSettings(newSettingId1, settingResult);
ASSERT_EQUALS(err, KErrNone);
//.........这里部分代码省略.........
示例4: suppressionsGlob
void suppressionsGlob() {
// Check for syntax errors in glob
{
Suppressions suppressions;
std::istringstream s("errorid:**.cpp\n");
ASSERT_EQUALS("Failed to add suppression. Syntax error in glob.", suppressions.parseFile(s));
}
// Check that globbing works
{
Suppressions suppressions;
std::istringstream s("errorid:x*.cpp\nerrorid:y?.cpp\nerrorid:test.c*");
ASSERT_EQUALS("", suppressions.parseFile(s));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "xyz.cpp", 1));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "xyz.cpp.cpp", 1));
ASSERT_EQUALS(false, suppressions.isSuppressed("errorid", "abc.cpp", 1));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "ya.cpp", 1));
ASSERT_EQUALS(false, suppressions.isSuppressed("errorid", "y.cpp", 1));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "test.c", 1));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "test.cpp", 1));
}
// Check that both a filename match and a glob match apply
{
Suppressions suppressions;
std::istringstream s("errorid:x*.cpp\nerrorid:xyz.cpp:1\nerrorid:a*.cpp:1\nerrorid:abc.cpp:2");
ASSERT_EQUALS("", suppressions.parseFile(s));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "xyz.cpp", 1));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "xyz.cpp", 2));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "abc.cpp", 1));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "abc.cpp", 2));
}
}
示例5: checkValid
void checkValid( int nKeys ) const {
ASSERT( bt() );
ASSERT( bt()->isHead() );
bt()->assertValid( order(), true );
ASSERT_EQUALS( nKeys, bt()->fullValidate( dl(), order() ) );
}
示例6: runChecks
void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) {
// check to make sure the appropriate error is present
(this->*check)("void f() {\n"
" int a;\n"
" a++;\n"
"}\n",
"");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
// suppress uninitvar globally
(this->*check)("void f() {\n"
" int a;\n"
" a++;\n"
"}\n",
"uninitvar");
ASSERT_EQUALS("", errout.str());
// suppress uninitvar globally, without error present
(this->*check)("void f() {\n"
" int a;\n"
" b++;\n"
"}\n",
"uninitvar");
ASSERT_EQUALS("[*]: (information) Unmatched suppression: uninitvar\n", errout.str());
// suppress uninitvar for this file only
(this->*check)("void f() {\n"
" int a;\n"
" a++;\n"
"}\n",
"uninitvar:test.cpp");
ASSERT_EQUALS("", errout.str());
// suppress uninitvar for this file only, without error present
(this->*check)("void f() {\n"
" int a;\n"
" b++;\n"
"}\n",
"uninitvar:test.cpp");
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar\n", errout.str());
// suppress all for this file only
(this->*check)("void f() {\n"
" int a;\n"
" a++;\n"
"}\n",
"*:test.cpp");
ASSERT_EQUALS("", errout.str());
// suppress all for this file only, without error present
(this->*check)("void f() {\n"
" int a;\n"
" b++;\n"
"}\n",
"*:test.cpp");
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: *\n", errout.str());
// suppress uninitvar for this file and line
(this->*check)("void f() {\n"
" int a;\n"
" a++;\n"
"}\n",
"uninitvar:test.cpp:3");
ASSERT_EQUALS("", errout.str());
// suppress uninitvar for this file and line, without error present
(this->*check)("void f() {\n"
" int a;\n"
" b++;\n"
"}\n",
"uninitvar:test.cpp:3");
ASSERT_EQUALS("[test.cpp:3]: (information) Unmatched suppression: uninitvar\n", errout.str());
// suppress uninitvar inline
(this->*check)("void f() {\n"
" int a;\n"
" // cppcheck-suppress uninitvar\n"
" a++;\n"
"}\n",
"");
ASSERT_EQUALS("", errout.str());
// suppress uninitvar inline
(this->*check)("void f() {\n"
" int a;\n"
" // cppcheck-suppress uninitvar\n"
"\n"
" a++;\n"
"}\n",
"");
ASSERT_EQUALS("", errout.str());
// suppress uninitvar inline
(this->*check)("void f() {\n"
" int a;\n"
" /* cppcheck-suppress uninitvar */\n"
" a++;\n"
"}\n",
"");
ASSERT_EQUALS("", errout.str());
//.........这里部分代码省略.........
示例7: TEST
TEST( LexNumCmp, Simple1 ) {
ASSERT_EQUALS( 0, LexNumCmp::cmp( "a.b.c", "a.b.c", false ) );
}
示例8: wrongMode_simple
void wrongMode_simple() {
// Read mode
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"r\");\n"
" fread(buffer, 5, 6, f);\n"
" rewind(f);\n"
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"r+\");\n"
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
// Write mode
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"w\");\n"
" fwrite(buffer, 5, 6, f);\n"
" rewind(f);\n"
" fread(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Read operation on a file that was opened only for writing.\n", errout.str());
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"w+\");\n"
" fread(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
// Append mode
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"a\");\n"
" fwrite(buffer, 5, 6, f);\n"
" rewind(f);\n"
" fread(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Read operation on a file that was opened only for writing.\n", errout.str());
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"a+\");\n"
" fread(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
// Variable declared locally
check("void foo() {\n"
" FILE* f = fopen(name, \"r\");\n"
" fwrite(buffer, 5, 6, f);\n"
" fclose(f);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
// Call unknown function
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"a\");\n"
" fwrite(buffer, 5, 6, f);\n"
" bar(f);\n"
" fread(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"a\");\n"
" fwrite(buffer, 5, 6, f);\n"
" clearerr(f);\n"
" fread(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Read operation on a file that was opened only for writing.\n", errout.str());
// freopen and tmpfile
check("void foo(FILE*& f) {\n"
" f = freopen(name, \"r\", f);\n"
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str());
// Crash tests
check("void foo(FILE*& f) {\n"
" f = fopen(name, mode);\n" // No assertion failure (#3830)
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void fopen(std::string const &filepath, std::string const &mode);"); // #3832
}
示例9: run
void run() {
insert( "{\"a\":\"b\"}" );
insert( "{\"a\":\"b\",\"x\":\"y\"}" );
insert( "{\"a\":\"c\"}" );
ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{\"a\":\"b\"}")));
}
示例10: returnReference2
void returnReference2() {
check("class Fred {\n"
" std::string &foo();\n"
"}\n"
"std::string &Fred::foo()\n"
"{\n"
" std::string s;\n"
" return s;\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Reference to auto variable returned.\n", errout.str());
check("class Fred {\n"
" std::vector<int> &foo();\n"
"};\n"
"std::vector<int> &Fred::foo()\n"
"{\n"
" std::vector<int> v;\n"
" return v;\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Reference to auto variable returned.\n", errout.str());
check("class Fred {\n"
" std::vector<int> &foo();\n"
"};\n"
"std::vector<int> &Fred::foo()\n"
"{\n"
" static std::vector<int> v;\n"
" return v;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("class Fred {\n"
" std::string &f();\n"
"};\n"
"std::string hello()\n"
"{\n"
" return \"hello\";\n"
"}\n"
"std::string &Fred::f()\n"
"{\n"
" return hello();\n"
"}");
ASSERT_EQUALS("[test.cpp:10]: (error) Reference to temporary returned.\n", errout.str());
check("class Fred {\n"
" std::string hello();\n"
" std::string &f();\n"
"};\n"
"std::string Fred::hello()\n"
"{\n"
" return \"hello\";\n"
"}\n"
"std::string &Fred::f()\n"
"{\n"
" return hello();\n"
"}");
ASSERT_EQUALS("[test.cpp:11]: (error) Reference to temporary returned.\n", errout.str());
check("class Bar;\n"
"Bar foo() {\n"
" return something;\n"
"}\n"
"Bar& bar() {\n"
" return foo();\n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str());
check("std::map<int, string> foo() {\n"
" return something;\n"
"}\n"
"std::map<int, string>& bar() {\n"
" return foo();\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Reference to temporary returned.\n", errout.str());
check("Bar foo() {\n"
" return something;\n"
"}\n"
"Bar& bar() {\n" // Unknown type - might be a typedef to a reference type
" return foo();\n"
"}");
ASSERT_EQUALS("", errout.str());
// Don't crash with function in unknown scope (#4076)
check("X& a::Bar() {}"
"X& foo() {"
" return Bar();"
"}");
}
示例11: returnReference1
void returnReference1() {
check("std::string &foo()\n"
"{\n"
" std::string s;\n"
" return s;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Reference to auto variable returned.\n", errout.str());
check("std::vector<int> &foo()\n"
"{\n"
" std::vector<int> v;\n"
" return v;\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Reference to auto variable returned.\n", errout.str());
check("std::vector<int> &foo()\n"
"{\n"
" static std::vector<int> v;\n"
" return v;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("std::string hello()\n"
"{\n"
" return \"hello\";\n"
"}\n"
"\n"
"std::string &f()\n"
"{\n"
" return hello();\n"
"}");
ASSERT_EQUALS("[test.cpp:8]: (error) Reference to temporary returned.\n", errout.str());
// make sure scope is used in function lookup
check("class Fred {\n"
" std::string hello() {\n"
" return std::string();\n"
" }\n"
"};\n"
"std::string &f() {\n"
" return hello();\n"
"}");
ASSERT_EQUALS("", errout.str());
check("std::string hello() {\n"
" return std::string();\n"
"}\n"
"\n"
"std::string &f() {\n"
" return hello();\n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str());
check("std::string hello() {\n"
" return \"foo\";\n"
"}\n"
"\n"
"std::string &f() {\n"
" return hello().substr(1);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("class Foo;\n"
"Foo hello() {\n"
" return Foo();\n"
"}\n"
"\n"
"Foo& f() {\n"
" return hello();\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Reference to temporary returned.\n", errout.str());
// make sure function overloads are handled properly
check("class Foo;\n"
"Foo & hello(bool) {\n"
" static Foo foo;\n"
" return foo;\n"
"}\n"
"Foo hello() {\n"
" return Foo();\n"
"}\n"
"\n"
"Foo& f() {\n"
" return hello(true);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("Foo hello() {\n"
" return Foo();\n"
"}\n"
"\n"
"Foo& f() {\n" // Unknown type - might be a reference
" return hello();\n"
"}");
ASSERT_EQUALS("", errout.str());
}
示例12: testautovar10
void testautovar10() { // #2930 - assignment of function parameter
check("void foo(char* p) {\n"
" p = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function.\n", errout.str());
check("void foo(int b) {\n"
" b = foo(b);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function.\n", errout.str());
check("void foo(char* p) {\n"
" if (!p) p = buf;\n"
" *p = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(char* p) {\n"
" if (!p) p = buf;\n"
" do_something(p);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(char* p) {\n"
" while (!p) p = buf;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(char* p) {\n"
" p = 0;\n"
" asm(\"somecmd\");\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(Foo* p) {\n"
" p = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function.\n", errout.str());
check("class Foo {};\n"
"void foo(Foo p) {\n"
" p = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Assignment of function parameter has no effect outside the function.\n", errout.str());
check("void foo(Foo p) {\n"
" p = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(int& p) {\n"
" p = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("double foo(double d) {\n" // #5005
" int i = d;\n"
" d = i;\n"
" return d;"
"}",false,false);
ASSERT_EQUALS("", errout.str());
}
示例13: invalid_switches
void invalid_switches() const {
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-a", "-v", "-q"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
ASSERT_EQUALS(true, args.quiet());
}
示例14: useClosedFile
void useClosedFile() {
check("void foo(FILE*& f) {\n"
" fclose(f);\n"
" fwrite(buffer, 5, 6, f);\n"
" clearerr(f);\n"
" fread(buffer, 5, 6, f);\n"
" ungetc('a', f);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n"
"[test.cpp:4]: (error) Used file that is not opened.\n"
"[test.cpp:5]: (error) Used file that is not opened.\n"
"[test.cpp:6]: (error) Used file that is not opened.\n", errout.str());
check("void foo(FILE*& f) {\n"
" if(!ferror(f)) {\n"
" fclose(f);\n"
" return;"
" }\n"
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(FILE*& f) {\n"
" fclose(f);\n"
" f = fopen(name, \"r\");\n"
" fread(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(FILE*& f) {\n"
" f = fopen(name, \"r\");\n"
" f = g;\n"
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" FILE* f;\n"
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n", errout.str());
check("void foo() {\n"
" FILE* f(stdout);\n"
" fwrite(buffer, 5, 6, f);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n" // #3965
" FILE* f[3];\n"
" f[0] = fopen(name, mode);\n"
" fclose(f[0]);\n"
"}");
ASSERT_EQUALS("", errout.str());
// #4368: multiple functions
check("static FILE *fp = NULL;\n"
"\n"
"void close()\n"
"{\n"
" fclose(fp);\n"
"}\n"
"\n"
"void dump()\n"
"{\n"
" if (fp == NULL) return;\n"
" fprintf(fp, \"Here's the output.\\n\");\n"
"}\n"
"\n"
"int main()\n"
"{\n"
" fp = fopen(\"test.txt\", \"w\");\n"
" dump();\n"
" close();\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("static FILE *fp = NULL;\n"
"\n"
"void close()\n"
"{\n"
" fclose(fp);\n"
"}\n"
"\n"
"void dump()\n"
"{\n"
" fclose(fp);\n"
" fprintf(fp, \"Here's the output.\\n\");\n"
"}");
ASSERT_EQUALS("[test.cpp:11]: (error) Used file that is not opened.\n", errout.str());
// #4466
check("void chdcd_parse_nero(FILE *infile) {\n"
" switch (mode) {\n"
" case 0x0300:\n"
" fclose(infile);\n"
" return;\n"
" case 0x0500:\n"
" fclose(infile);\n"
//.........这里部分代码省略.........
示例15: returnIssues
void returnIssues() {
check("void* foo(int i) {\n"
" return i;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an integer in a function with pointer return type is not portable.\n", errout.str());
check("void* foo(int* i) {\n"
" return i;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void* foo() {\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int foo(int i) {\n"
" return i;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int foo(char* c) {\n"
" return c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
check("int foo(char* c) {\n"
" return 1+c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str());
check("std::string foo(char* c) {\n"
" return c;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int foo(char *a, char *b) {\n" // #4486
" return a + 1 - b;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("struct s {\n" // 4642
" int i;\n"
"};\n"
"int func(struct s *p) {\n"
" return 1 + p->i;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("static void __iomem *f(unsigned int port_no) {\n"
" void __iomem *mmio = hpriv->mmio;\n"
" return mmio + (port_no * 0x80);\n"
"}");
ASSERT_EQUALS("", errout.str());
// #7247: dont check return statements in nested functions..
check("int foo() {\n"
" struct {\n"
" const char * name() { return \"abc\"; }\n"
" } table;\n"
"}");
ASSERT_EQUALS("", errout.str());
// #7451: Lambdas
check("const int* test(std::vector<int> outputs, const std::string& text) {\n"
" auto it = std::find_if(outputs.begin(), outputs.end(), \n"
" [&](int ele) { return \"test\" == text; });\n"
" return nullptr;\n"
"}");
ASSERT_EQUALS("", errout.str());
}