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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:52:25+00:00 2026-06-04T11:52:25+00:00

I have the following C code that uses sqlite3: if(SQLITE_OK == sqlite3_initialize()) { self->db_open_result

  • 0

I have the following C code that uses sqlite3:

if(SQLITE_OK == sqlite3_initialize()) {
    self->db_open_result = sqlite3_open(self->db_uri, &(self->db));
} else {
    self->db_open_result = SQLITE_ERROR;
}

Obviously I have a pretty high confidence that the code is correct and will behave as expected. However, I am measuring code coverage of my unit tests using gcov/lcov and I’m curious about how I might get my coverage number to 100% in this case. Under normal circumstances sqlite3_initialize() is never going to fail, so the else clause will never execute.

Is there a way to cause this to fail that isn’t totally disruptive?

  • 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-06-04T11:52:27+00:00Added an answer on June 4, 2026 at 11:52 am

    You want your unit-tests to test your code. But you also want to know that all of your test code has been properly exercised. One way to do that is to use “mocking”, i.e. you replace your actual libraries (such as SQLite) with fake, or “mock” libraries and then run your programs against these fake libraries.

    Whether this library replacement is done at compile time or runtime is really incidental, but in C it’s easier to do it at compile time. You can do this mocking by hand, or you can use a tool such as Cmock.

    In the faked library, you then provoke various errors and failures. Notably, the faked library doesn’t even have to do anything or even keep track of much or any state, you can often get quite far by returning “OK” or “FAIL”.

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

Sidebar

Related Questions

I have the following code that uses a for loop and I would like
I have the following code that uses 'paste' and AWK script inside Perl. use
I have the following C# code that uses DLLImport. using System; namespace LvFpga {
I have the following code that uses Sequence objects to read data from a
I have the following code, that uses session but i have an error in
I have some inherited code that uses hibernate. I'm getting the following error: Caused
I have the following code that uses the SqlClient.ExecuteScalar method to return an ID
I have the following jQuery code that uses the scrollTo and localScroll plugins from
I have the following code that creates an object in JavaScript. It uses prototype
I have following code i want that window opened uses Ext.layout.BorderLayout and also on

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.