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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:04:44+00:00 2026-05-23T02:04:44+00:00

Using the CUTE unit test framework I have the following classes: const std::size_t COARSE_MODEL_COUNT

  • 0

Using the CUTE unit test framework I have the following classes:

const std::size_t COARSE_MODEL_COUNT = 4;

class ModelType
{
   public:

      explicit ModelType(std::size_t aModelNumber) : theModelNumber(aModelNumber){}

      virtual operator size_t(){ return theModelNumber; }

   protected:

      std::size_t theModelNumber;
};

class CoarseModelType : public ModelType
{
   public:

      explicit CoarseModelType(std::size_t aModelNumber) : ModelType(aModelNumber)
      {
         if (COARSE_MODEL_COUNT <= aModelNumber)
         {
            throw std::invalid_argument("Invalid model number selected for \
                                        this model type.");
         }
      }
};

with the following unit test:

void ModelTypeTest::testCoarseModelConstructor()
{
   //greater than test
   ASSERT_THROWS(CoarseModelType(COARSE_MODEL_COUNT+1), std::invalid_argument);

   //equal to
   ASSERT_THROWS(CoarseModelType(COARSE_MODEL_COUNT), std::invalid_argument);
}

If I comment out the second ASSERT_THROWS the unit test passes correctly. If I leave it in it fails. I would think that using the <= operator on a std::size_t type would recognize the == component but it’s not. The ASSERT_THROWS is a macro.

We’re on Linux using gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46). Is there some sort of implicit conversion or something going on that I’m not aware of? We’re all scratching our heads on this one.

Edit:

The following does throw an error within the unit test and is registered as an error rather than a fail. The exception is thrown before the second ASSERT_THROWS statement has a chance to fail:

void ModelTypeTest::testCoarseModelConstructor()
{
   //greater than test
   ASSERT_THROWS(CoarseModelType(COARSE_MODEL_COUNT+1), std::invalid_argument);

   if(COARSE_MODEL_COUNT <= COARSE_MODEL_COUNT){
      throw std::invalid_argument("wtf");
   }

   //equal to
   ASSERT_THROWS(CoarseModelType(COARSE_MODEL_COUNT), std::invalid_argument);
}

So this is an issue with CUTE. I just don’t know the how or why in regards to the macro interaction with the constructor code.

  • 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-23T02:04:45+00:00Added an answer on May 23, 2026 at 2:04 am

    (Ahem) I think the ASSERT_THROWS macro is doing something you’re not aware of. Instead of

    CoarseModelType(COARSE_MODEL_COUNT)
    

    try

    CoarseModelType dummy(COARSE_MODEL_COUNT)
    

    and see what happens. The first is an odd way to invoke the constructor, and a clumsy macro might turn it into something that the compiler interprets differently.

    (Note: you can use gcc -E to preprocess the source code without compiling it, expanding macros in place so that you can see what they’re doing.)

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

Sidebar

Related Questions

Using the following code: public class Panel extends SurfaceView { // ...... // in
Should client-side templates like the following (using underscore's templating engine): <p class=foo><%= bar %></p>
There are some people in my office who insist on using cute stationery and
When i uploaded the my website online. i Upload the site using cute ftp.
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using SVN you can right click a folder TEST and add it to the
Using Core Data. Let's say we have models for Team and Player. Assume: -Each
Using the following as an example (with $db being a previously created database connection
Using SolrNet for querying & faceting. I have a combination of int, tdate and

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.