简体   繁体   中英

Invalid parameter passed to C runtime function with QTest

I am developing a Qt project with Qt creator, all works fine, but when i came to the unit testing part using QTest, after compilation I get the error "Invalid parameter passed to C run-time function".

Can anyone help me to find the source of the problem? Is it due to the use of cstdio functions or has it something to do with the .pro configuration?

This is a test method I implemented and did not work:

void TestFichier::testLoad()
{
    Fichier a;
    a.load("input.txt");
    FILE *f=fopen("input.txt","rb");
    int c;
    int i,*tab=a.getHexValues();
    for (i=0;i<3;i++)
        c=fgetc(f);
    fclose(f);
    QCOMPARE(tab[2],c);
}

Fichier is a class I created with a method load .

MSDN fgetc documentation states:

If [the parameter] stream is NULL, fgetc and fgetwc invoke the invalid parameter handler, as described in Parameter Validation .

So you should check if fopen returns NULL , and in that case, find the type of error with errno .

Probably, your problem is that you make some errors while working with dynamical memory. For example, you can use pointers to unallocated memory, or so. Check your code at getHexValues() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM