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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:31:35+00:00 2026-05-27T14:31:35+00:00

I started writing a little program in C as a development excercise and I

  • 0

I started writing a little program in C as a development excercise and I want to have a lot of unit test for this programs. The problem is that from time to time it uses fread/fwrite and other standard functions – I don’t want my unit tests to open any file, so it would be great if I could write stub for fread/fwrite.

Anyone have solution for this problem?

Thanks in advance for answers!

edit: I forgot about one important thing: stub for read need to behave differently in different tests. In one, read return value must be < then passed number of elements to read (simulates too early eof) and in other read return value must be equal to passed number of elements to read

  • 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-27T14:31:35+00:00Added an answer on May 27, 2026 at 2:31 pm

    There are multiple options:

    1. Turn fopen(), fread(), etc into indirect function calls, through function pointers. For normal operation set them to point to fopen(), etc. For testing, set them to point to your functions.
    2. Define your replacement functions myfopen(), myfread(), etc. Compile the main part of the program with the macros named fopen, fread, etc and expanding into myfopen, myfread, etc.
    3. Define your own fopen(), fread(), etc. Play with the linker to make them replace the ones from the standard library. This is very error-prone and hard to do.
    4. Hook fopen(), fread(), etc functions using disassembly, assembly and run-time code patching. This isn’t easy either.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started writing a Macro in Visual Studio 2005 like this: Public Sub
I just started writing pub/sub and the way that I doing this is that
I have just started writing my own JavaScript Framework (just for the learning experience),
I have just installed C# 2008 Express Edition 2008 and started writing code. My
I have very little experience designing databases, and now I want to create a
I've started writing an ActiveX control that makes use of sockets. Applications that use
I've started to construct a builder so that I can easily create test data
I am currently writing a little bootstrap code for a service that can be
Hi I'm having some problem with a PHP page: I'm writing a little CMS
In writing an install script, I quickly found that I'd have cross-platform issues, 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.