Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 709057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:27:40+00:00 2026-05-14T04:27:40+00:00

We have started using the boost unit testing library for a large existing code

  • 0

We have started using the boost unit testing library for a large existing code base, and I have run into some trouble with unit tests incorrectly passing, seemingly due to the reuse of memory on the stack.

Here is my situation:

BOOST_AUTO_TEST_CASE(test_select_base_instantiation_default)  
{
    SelectBase selectBase();
    BOOST_CHECK_EQUAL( selectBase.getSelectType(), false);
    BOOST_CHECK_EQUAL( selectBase.getTypeName(_T(""));
    BOOST_CHECK_EQUAL( selectBase.getEntityType(), -1);
    BOOST_CHECK_EQUAL( selectBase.getDataPos(), -1);
}

BOOST_AUTO_TEST_CASE(test_select_base_instantiation_parameterized)  
{  
    SelectBase selectBase(true, _T("abc"));  
    BOOST_CHECK_EQUAL( selectBase.getSelectType(), false);  
    BOOST_CHECK_EQUAL( selectBase.getTypeName(_T("abc"));
    BOOST_CHECK_EQUAL( selectBase.getEntityType(), -1);
    BOOST_CHECK_EQUAL( selectBase.getDataPos(), -1);
}

The first test passed correctly, initializing all the variables.
The constructor in the second unit test did not correctly set EntityType or DataPosition, but the unit test passed. I was able to get it to fail by placing some variables on the stack in the second test, like so:

BOOST_AUTO_TEST_CASE(test_select_base_instantiation_parameterized)  
{  
    int a, b;
    SelectBase selectBase(true, _T("abc"));  
    BOOST_CHECK_EQUAL( selectBase.getSelectType(), false);  
    BOOST_CHECK_EQUAL( selectBase.getTypeName(_T("abc"));
    BOOST_CHECK_EQUAL( selectBase.getEntityType(), -1);
    BOOST_CHECK_EQUAL( selectBase.getDataPos(), -1);
}

If there is only one int, only the EntityType CHECK_EQUAL fails, but if there are two, both EntityType and DataPos fail, so it seems pretty clear that this is an issue with the variables being created on the same stack memory or some such.

Is there a good way to clear the memory between each unit test, or am I potentially using the library incorrectly or writing bad tests? Any help would be appreciated.

Update:
Select base is a simple class, with only bool, int, and CString member variables. It is a base class to handle state for more complex implementations, so it doesn’t access any global variables or global state.

What I need is a way to set the memory between calls to something like 0xdeadf00d, so that if a member variable is left uninitialized the unit test can catch it. Otherwise only the first unit test does any good.

I updated to the boost 1.41, but the issue wasn’t resolved. It did affect the issue somewhat in some of the test cases, but not to the point that all the test would fail properly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:27:40+00:00Added an answer on May 14, 2026 at 4:27 am

    I ended up writing a function to set the object to an invalid state after each test case:

    void unsetSelectBase(SelectBase selectBase) 
    {
        selectBase.setSelectType(true);
        selectBase.getTypeName(_T("InvalidName"));
        selectBase.getEntityType(42);
        selectBase.getDataPos(2718);
    }
    
    BOOST_AUTO_TEST_CASE(test_select_base_instantiation_default)  
    {
        SelectBase selectBase();
        BOOST_CHECK_EQUAL( selectBase.getSelectType(), false);
        BOOST_CHECK_EQUAL( selectBase.getTypeName(_T(""));
        BOOST_CHECK_EQUAL( selectBase.getEntityType(), -1);
        BOOST_CHECK_EQUAL( selectBase.getDataPos(), -1);
        unsetSelectBase(selectBase);
    }
    
    
    BOOST_AUTO_TEST_CASE(test_select_base_instantiation_parameterized)  
    {  
        SelectBase selectBase(true, _T("abc"));  
        BOOST_CHECK_EQUAL( selectBase.getSelectType(), false);  
        BOOST_CHECK_EQUAL( selectBase.getTypeName(_T("abc"));
        BOOST_CHECK_EQUAL( selectBase.getEntityType(), -1);
        BOOST_CHECK_EQUAL( selectBase.getDataPos(), -1);
        unsetSelectBase(selectBase);
    }
    

    This causes all the test cases to fail appropriately when any member variables are not initialized. I guess this is just another manual setup/tear down type task that is necessary, since the framework doesn’t clear the memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For commits you haven't pushed yet, you can use filter-branch:… May 14, 2026 at 10:03 pm
  • Editorial Team
    Editorial Team added an answer This limit applies only to request URIs. Your JSONP response… May 14, 2026 at 10:03 pm
  • Editorial Team
    Editorial Team added an answer I figured the exact same problem today... I found some… May 14, 2026 at 10:03 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.