0

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.

4

2 回答 2

1

MSDN fgetc 文档指出:

如果 [参数] 流为 NULL,则 fgetc 和 fgetwc 调用无效参数处理程序,如参数验证中所述。

因此,您应该检查是否fopen返回NULL,在这种情况下,使用 查找错误类型errno

于 2012-11-19T20:07:26.390 回答
0

可能,您的问题是您在使用动态内存时犯了一些错误。例如,您可以使用指向未分配内存的指针,等等。getHexValues()在方法中检查您的代码。

于 2012-11-19T18:49:47.017 回答