您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ ASSERT_EQUALS函数代码示例

51自学网 2021-06-01 19:37:30
  C++
这篇教程C++ ASSERT_EQUALS函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中ASSERT_EQUALS函数的典型用法代码示例。如果您正苦于以下问题:C++ ASSERT_EQUALS函数的具体用法?C++ ASSERT_EQUALS怎么用?C++ ASSERT_EQUALS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ASSERT_EQUALS函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;}
开发者ID:vsaw,项目名称:HJI-Approx,代码行数:61,


示例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());}
开发者ID:DreamerKing,项目名称:mongo,代码行数:46,


示例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);//.........这里部分代码省略.........
开发者ID:kuailexs,项目名称:symbiandump-os1,代码行数:101,


示例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));        }    }
开发者ID:Flapstah,项目名称:cppcheck,代码行数:33,


示例5: checkValid

 void checkValid( int nKeys ) const {     ASSERT( bt() );     ASSERT( bt()->isHead() );     bt()->assertValid( order(), true );     ASSERT_EQUALS( nKeys, bt()->fullValidate( dl(), order() ) ); }
开发者ID:catap,项目名称:mongo,代码行数:6,


示例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());//.........这里部分代码省略.........
开发者ID:Flapstah,项目名称:cppcheck,代码行数:101,


示例7: TEST

 TEST( LexNumCmp, Simple1 ) {     ASSERT_EQUALS( 0, LexNumCmp::cmp( "a.b.c", "a.b.c", false ) ); }
开发者ID:ANTco,项目名称:mongo,代码行数:3,


示例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    }
开发者ID:0x20e,项目名称:cppcheck,代码行数:87,


示例9: run

 void run() {     insert( "{/"a/":/"b/"}" );     insert( "{/"a/":/"b/",/"x/":/"y/"}" );     insert( "{/"a/":/"c/"}" );     ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{/"a/":/"b/"}"))); }
开发者ID:daveh86,项目名称:mongo,代码行数:6,


示例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();"              "}");    }
开发者ID:JuriGagarin,项目名称:cppcheck,代码行数:89,


示例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());    }
开发者ID:JuriGagarin,项目名称:cppcheck,代码行数:96,


示例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());    }
开发者ID:JuriGagarin,项目名称:cppcheck,代码行数:62,


示例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()); }
开发者ID:Dmitry-Me,项目名称:cppcheck,代码行数:6,


示例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"//.........这里部分代码省略.........
开发者ID:0x20e,项目名称:cppcheck,代码行数:101,


示例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());    }
开发者ID:DivineLawnmower,项目名称:cppcheck,代码行数:71,


示例16: testScanfArgument

    void testScanfArgument() {        check("void foo() {/n"              "    scanf(/"%1d/", &foo);/n"              "    sscanf(bar, /"%1d/", &foo);/n"              "    scanf(/"%1u%1u/", &foo, bar());/n"              "    scanf(/"%*1x %1x %29s/", &count, KeyName);/n" // #3373              "    fscanf(f, /"%7ms/", &ref);/n" // #3461              "    sscanf(ip_port, /"%*[^:]:%4d/", &port);/n" // #3468              "}");        ASSERT_EQUALS("", errout.str());        check("void foo() {/n"              "    scanf(/"/", &foo);/n"              "    scanf(/"%1d/", &foo, &bar);/n"              "    fscanf(bar, /"%1d/", &foo, &bar);/n"              "    scanf(/"%*1x %1x %29s/", &count, KeyName, foo);/n"              "}");        ASSERT_EQUALS("[test.cpp:2]: (warning) scanf format string has 0 parameters but 1 are given./n"                      "[test.cpp:3]: (warning) scanf format string has 1 parameters but 2 are given./n"                      "[test.cpp:4]: (warning) fscanf format string has 1 parameters but 2 are given./n"                      "[test.cpp:5]: (warning) scanf format string has 2 parameters but 3 are given./n", errout.str());        check("void foo() {/n"              "    scanf(/"%1d/");/n"              "    scanf(/"%1u%1u/", bar());/n"              "    sscanf(bar, /"%1d%1d/", &foo);/n"              "    scanf(/"%*1x %1x %29s/", &count);/n"              "}");        ASSERT_EQUALS("[test.cpp:2]: (error) scanf format string has 1 parameters but only 0 are given./n"                      "[test.cpp:3]: (error) scanf format string has 2 parameters but only 1 are given./n"                      "[test.cpp:4]: (error) sscanf format string has 2 parameters but only 1 are given./n"                      "[test.cpp:5]: (error) scanf format string has 2 parameters but only 1 are given./n", errout.str());        check("void foo() {/n"              "    char input[10];/n"              "    char output[5];/n"              "    sscanf(input, /"%3s/", output);/n"              "    sscanf(input, /"%4s/", output);/n"              "    sscanf(input, /"%5s/", output);/n"              "}", false);        ASSERT_EQUALS("[test.cpp:6]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it./n", errout.str());        check("void foo() {/n"              "    char input[10];/n"              "    char output[5];/n"              "    sscanf(input, /"%s/", output);/n"              "    sscanf(input, /"%3s/", output);/n"              "    sscanf(input, /"%4s/", output);/n"              "    sscanf(input, /"%5s/", output);/n"              "}", true);        ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Width 3 given in format string (no. 1) is smaller than destination buffer 'output[5]'./n"                      "[test.cpp:7]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it./n"                      "[test.cpp:4]: (warning) scanf without field width limits can crash with huge input data./n", errout.str());        check("void foo() {/n"              "    const size_t BUFLENGTH(2048);/n"              "    typedef char bufT[BUFLENGTH];/n"              "    bufT line= {0};/n"              "    bufT projectId= {0};/n"              "    const int scanrc=sscanf(line, /"Project(///"{%36s}///")/", projectId);/n"              "    sscanf(input, /"%5s/", output);/n"              "}", true);        ASSERT_EQUALS("", errout.str());    }
开发者ID:0x20e,项目名称:cppcheck,代码行数:64,


示例17: suppressionsFileNameWithExtraPath

 void suppressionsFileNameWithExtraPath() {     // Ticket #2797     Suppressions suppressions;     suppressions.addSuppression("errorid", "./a.c", 123);     ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "a.c", 123)); }
开发者ID:Flapstah,项目名称:cppcheck,代码行数:6,


示例18: testPrintfArgument

    void testPrintfArgument() {        check("void foo() {/n"              "    printf(/"%u/");/n"              "    printf(/"%u%s/", 123);/n"              "    printf(/"%u%s%d/", 0, bar());/n"              "    printf(/"%u%%%s%d/", 0, bar());/n"              "    printf(/"%udfd%%dfa%s%d/", 0, bar());/n"              "    fprintf(stderr,/"%u%s/");/n"              "    snprintf(str,10,/"%u%s/");/n"              "    sprintf(string1, /"%-*.*s/", 32, string2);/n" // #3364              "    snprintf(a, 9, /"%s%d/", /"11223344/");/n" // #3655              "}");        ASSERT_EQUALS("[test.cpp:2]: (error) printf format string has 1 parameters but only 0 are given./n"                      "[test.cpp:3]: (error) printf format string has 2 parameters but only 1 are given./n"                      "[test.cpp:4]: (error) printf format string has 3 parameters but only 2 are given./n"                      "[test.cpp:5]: (error) printf format string has 3 parameters but only 2 are given./n"                      "[test.cpp:6]: (error) printf format string has 3 parameters but only 2 are given./n"                      "[test.cpp:7]: (error) fprintf format string has 2 parameters but only 0 are given./n"                      "[test.cpp:8]: (error) snprintf format string has 2 parameters but only 0 are given./n"                      "[test.cpp:9]: (error) sprintf format string has 3 parameters but only 2 are given./n"                      "[test.cpp:10]: (error) snprintf format string has 2 parameters but only 1 are given./n", errout.str());        check("void foo(char *str) {/n"              "    printf(/"/", 0);/n"              "    printf(/"%u/", 123, bar());/n"              "    printf(/"%u%s/", 0, bar(), 43123);/n"              "}");        ASSERT_EQUALS("[test.cpp:2]: (warning) printf format string has 0 parameters but 1 are given./n"                      "[test.cpp:3]: (warning) printf format string has 1 parameters but 2 are given./n"                      "[test.cpp:4]: (warning) printf format string has 2 parameters but 3 are given./n", errout.str());        check("void foo() {/n" // swprintf exists as MSVC extension and as standard function: #4790              "    swprintf(string1, L/"%u/", 32, string2);/n" // MSVC implementation              "    swprintf(string1, L/"%s%s/", L/"a/", string2);/n" // MSVC implementation              "    swprintf(string1, 6, L/"%u/", 32, string2);/n" // Standard implementation              "    swprintf(string1, 6, L/"%u%s/", 32, string2);/n" // Standard implementation              "}");        ASSERT_EQUALS("[test.cpp:2]: (warning) swprintf format string has 1 parameters but 2 are given./n"                      "[test.cpp:4]: (warning) swprintf format string has 1 parameters but 2 are given./n", errout.str());        check("void foo(char *str) {/n"              "    printf(/"%u/", 0);/n"              "    printf(/"%u%s/", 123, bar());/n"              "    printf(/"%u%s%d/", 0, bar(), 43123);/n"              "    printf(/"%u%%%s%d/", 0, bar(), 43123);/n"              "    printf(/"%udfd%%dfa%s%d/", 0, bar(), 43123);/n"              "    printf(/"%/"PRId64/"/n/", 123);/n"              "    fprintf(stderr,/"%/"PRId64/"/n/", 123);/n"              "    snprintf(str,10,/"%/"PRId64/"/n/", 123);/n"              "    fprintf(stderr, /"error: %m/n/");/n" // #3339              "    printf(/"string: %.*s/n/", len, string);/n" // #3311              "    fprintf(stderr, /"%*cText./n/", indent, ' ');/n" // #3313              "    sprintf(string1, /"%*/", 32);/n" // #3364              "}");        ASSERT_EQUALS("", errout.str());        check("void foo(char* s, const char* s2, std::string s3, int i) {/n"              "    printf(/"%s%s/", s, s2);/n"              "    printf(/"%s/", i);/n"              "    printf(/"%i%s/", i, i);/n"              "    printf(/"%s/", s3);/n"              "    printf(/"%s/", /"s4/");/n"              "    printf(/"%u/", s);/n"              "}");        ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires a char* given in the argument list./n"                      "[test.cpp:4]: (warning) %s in format string (no. 2) requires a char* given in the argument list./n"                      "[test.cpp:5]: (warning) %s in format string (no. 1) requires a char* given in the argument list./n", errout.str());        check("void foo(const int* cpi, const int ci, int i, int* pi, std::string s) {/n"              "    printf(/"%n/", cpi);/n"              "    printf(/"%n/", ci);/n"              "    printf(/"%n/", i);/n"              "    printf(/"%n/", pi);/n"              "    printf(/"%n/", s);/n"              "    printf(/"%n/", /"s4/");/n"              "}");        ASSERT_EQUALS("[test.cpp:2]: (warning) %n in format string (no. 1) requires a pointer to an non-const integer given in the argument list./n"                      "[test.cpp:3]: (warning) %n in format string (no. 1) requires a pointer to an non-const integer given in the argument list./n"                      "[test.cpp:4]: (warning) %n in format string (no. 1) requires a pointer to an non-const integer given in the argument list./n"                      "[test.cpp:6]: (warning) %n in format string (no. 1) requires a pointer to an non-const integer given in the argument list./n"                      "[test.cpp:7]: (warning) %n in format string (no. 1) requires a pointer to an non-const integer given in the argument list./n", errout.str());        check("class foo {};/n"              "void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, unsigned int u) {/n"              "    printf(/"%X/", f);/n"              "    printf(/"%c/", /"s4/");/n"              "    printf(/"%o/", d);/n"              "    printf(/"%x/", cpi);/n"              "    printf(/"%o/", b);/n"              "    printf(/"%X/", bp);/n"              "    printf(/"%X/", u);/n"              "    printf(/"%X/", i);/n"              "}");        ASSERT_EQUALS("[test.cpp:3]: (warning) %X in format string (no. 1) requires an integer given in the argument list./n"                      "[test.cpp:4]: (warning) %c in format string (no. 1) requires an integer given in the argument list./n"                      "[test.cpp:5]: (warning) %o in format string (no. 1) requires an integer given in the argument list./n", errout.str());        check("class foo {};/n"              "void foo(const int* cpi, foo f, bar b, bar* bp, double d, unsigned int u, unsigned char uc) {/n"              "    printf(/"%i/", f);/n"//.........这里部分代码省略.........
开发者ID:0x20e,项目名称:cppcheck,代码行数:101,


示例19: suppressionsBadId1

 void suppressionsBadId1() {     Suppressions suppressions;     std::istringstream s("123");     ASSERT_EQUALS("Failed to add suppression. Invalid id /"123/"", suppressions.parseFile(s)); }
开发者ID:Flapstah,项目名称:cppcheck,代码行数:5,


示例20: which_test_method

 void which_test_method() const {     const char* argv[] = {"./test_runner", "TestClass::TestMethod"};     options args(sizeof argv / sizeof argv[0], argv);     ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); }
开发者ID:Dmitry-Me,项目名称:cppcheck,代码行数:5,


示例21: no_test_method

 void no_test_method() const {     const char* argv[] = {"./test_runner"};     options args(sizeof argv / sizeof argv[0], argv);     ASSERT_EQUALS("", args.which_test()); }
开发者ID:Dmitry-Me,项目名称:cppcheck,代码行数:5,


示例22: quiet

 void quiet() const {     const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-q"};     options args(sizeof argv / sizeof argv[0], argv);     ASSERT_EQUALS(true, args.quiet()); }
开发者ID:Dmitry-Me,项目名称:cppcheck,代码行数:5,


示例23: validate

 void validate(){     ASSERT_EQUALS(target.take() , nthreads * iterations); }
开发者ID:anagri,项目名称:mongo,代码行数:3,


示例24: multiple_testcases

 void multiple_testcases() const {     const char* argv[] = {"./test_runner", "TestClass::TestMethod", "Ignore::ThisOne"};     options args(sizeof argv / sizeof argv[0], argv);     ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); }
开发者ID:Dmitry-Me,项目名称:cppcheck,代码行数:5,


示例25: isDirectory

 void isDirectory() const {     ASSERT_EQUALS(false, FileLister::isDirectory("readme.txt"));     ASSERT_EQUALS(true, FileLister::isDirectory("lib")); }
开发者ID:rainrambler,项目名称:cpp2go,代码行数:4,



注:本文中的ASSERT_EQUALS函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ ASSERT_ERR函数代码示例
C++ ASSERT_EQUAL函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。