2015-11-12 26 views
0

這裏是我的代碼,xmlDoc中* D總是被重置到零在 「EXTEST,try1」爲什麼shared_variable復位到零的GTEST

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 
} 
+0

c有課? –

+0

@ machine_1我調用libxml2,它的c庫文件 – nwaicaethi

回答

1

你有兩個不同的變量,都稱爲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變量的值,而不是創建一個新的。

+0

thx,它解決了我的問題。 – nwaicaethi

+0

@nwaicaethi如果你接受了這個答案,那會很好。 –