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 6585233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:38:10+00:00 2026-05-25T16:38:10+00:00

Relevant code, this is from UnitTest++/TestRunner.h : class TestRunner { public: explicit TestRunner(TestReporter& reporter);

  • 0

Relevant code, this is from UnitTest++/TestRunner.h:

class TestRunner
{
public:
    explicit TestRunner(TestReporter& reporter);
    ~TestRunner();

    template <class Predicate>
    int RunTestsIf(TestList const& list, char const* suiteName, 
                   const Predicate& predicate, int maxTestTimeInMs) const
    {
        Test* curTest = list.GetHead();

        while (curTest != 0)
        {
            if (IsTestInSuite(curTest,suiteName) && predicate(curTest))
            {
                RunTest(m_result, curTest, maxTestTimeInMs);
            }

            curTest = curTest->next;
        }

        return Finish();
    }   

private:
    TestReporter* m_reporter;
    TestResults* m_result;
    Timer* m_timer;

    int Finish() const;
    bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
    void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
};

Here is my predicate class I am trying to modify to let it do what I want:

class ListFilterRemember {
    char **list;
    int n;
    Test **testsAlreadyRun;
    int index_tar;
    int max_allocd;
public:
    ListFilterRemember(char **list_, int count) {
                int testCount = 0;
        Test* curTest = Test::GetTestList().GetHead();
        while (curTest != 0) {
            testCount++;
        }
                list = list_; n = count; max_allocd = testCount;
        testsAlreadyRun = new Test *[max_allocd];
        index_tar = 0;
    }
    bool operator()(const Test* const t) const {
        for (int i=0;i<index_tar;++i) {
            if (testsAlreadyRun[i] == t) { return false; }
        }
        for (int i=0;i<n;++i) {
            std::string dot_cpp_appended = std::string(list[i]) + ".cpp";
            if (!strcasecmp(t->m_details.testName, list[i]) ||
                    !strcasecmp(t->m_details.suiteName, list[i]) ||
                    !strcasecmp(t->m_details.filename, list[i]) ||
                    !strcasecmp(t->m_details.filename, dot_cpp_appended.c_str()) || (
                            filename_dir_prefix_len < (int)strlen(t->m_details.filename) && ( // ensure the ptr arith in next 2 lines doesn't go out of bounds
                                    !strcasecmp(t->m_details.filename+filename_dir_prefix_len, list[i]) ||
                                    !strcasecmp(t->m_details.filename+filename_dir_prefix_len, dot_cpp_appended.c_str())
                            )
                    ) || (
                            std::string::npos != findCaseInsensitive(t->m_details.testName,list[i])
                    )
            ) {
                // erring on the side of matching more tests
                //printf(" running\n");
                if (index_tar >= max_allocd) throw std::runtime_error("Did not allocate! Segfault here.");
                testsAlreadyRun[index_tar] = (Test *)t;
                index_tar += 1;
                return true;
            }
        }
        //printf(" not running\n");
        return false;
    }
    ~ListFilterRemember() {
        delete[] testsAlreadyRun;
    }
};

You see the way that it’s defined in TestRunner.h attaches a const qualifier which makes it impossible for my operator () function to make changes to member variables. I need to make those changes so I can remember which tests I’ve already run so I don’t run them again. The reason why there might be risk of them running again is that I intend to run RunTestsIf() multiple times.

I enter a list of tests at the command line to specify which tests I want to run based on their names. That is what all of the string matching code is for. I still want to use those, but this time I want to improve it so that the tests I specify will run in the order that i specify them in. In order to do this I have to move the test runner so that I loop over my specified test list and match based on them one by one.

Ideas? I’d go nuke the const in the UnitTest++ code but I don’t want to break things if I don’t have to.

  • 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-25T16:38:11+00:00Added an answer on May 25, 2026 at 4:38 pm

    You could use the mutable keyword, but the way the test is structured suggests that the test runner might not reuse the same instance of the predicate, so your changes might be lost between tests. Of course, if the posted code is the entire test runner, then it looks like it does call the same Predicate instance every time.

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

Sidebar

Related Questions

Here's the relevant code: public static void printBoarders (Territory x) { int t =
Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) {
Here's the relevant bit of the source code: class Dice { String name ;
here is the relevent code snippet: public static Rand searchCount (int[] x) { int
I'm serving up an image from a database using an IHttpHandler. The relevant code
How I can prevent the last line of this code from compiling? #include <boost/optional.hpp>
I have a problem with my JDBC code. This is the relevant code: /**
I'm doing this from code but it should be equivalent to jsp.. Trying to
I'm embedding MSBuild directly into a more complex build tool. The relevant code looks
I'm having some trouble with the jQuery hover method. Here's the relevant JavaScript code:

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.