为什么在gtest中将shared_variable重置为nil

Why shared_variable is reset to nil in gtest

本文关键字:nil variable gtest 中将 shared 为什么      更新时间:2023-10-16

这是我的代码,xmlDoc*d在"ExTest,try1"中总是重置为零

ex_test.cpp

typedef const char* str;
class ExTest : public ::testing::Test {
protected:
    static str html;
    static xmlDoc *d;
    static void SetUpTestCase() {
        html = "<html></html>";
        xmlDoc *d = xmlParseDoc((const xmlChar *) html);
        d;//0x685a30
    }
};
str ExTest::html = NULL;
xmlDoc *ExTest::d = NULL;
TEST_F(ExTest, try1) {
    d; //nil
}

您有两个不同的变量,都称为d

static xmlDoc *d; <- here's one
static void SetUpTestCase() {
    html = "<html></html>";
    xmlDoc *d = ... <- here's the other

你的意思可能是:

    d = xmlParseDoc((const xmlChar *) html);

这将设置现有d变量的值,而不是创建新的值。