--
---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/f889edc4-ebe0-4834-af01-b1643346f478%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
virtual std::string getUrlAsString( const std::string &url ) const {
// TODO
return std::string( );
}
It returns empty string. Please, see this code:
TEST(HtmlParser, NoData) {char *html;HttpFetchMock mock;HtmlParser parser(mock);EXPECT_CALL(mock, getUrlAsString("http://example.net")).WillOnce(Return(std::string(html)));}
class Mock has a method called "getUrlAsString". This string ".WillOnce" means that we will call this method one time. This string "Return(std::string(html)" means that this method return empty string.
Sorry for my English in advance.
What does this mean? "In the code you published in this email, there is no code calling "getUrlAsString.""
I have this method in the class HttpFetch:
virtual std::string getUrlAsString( const std::string &url ) const {// TODOreturn std::string( );}It returns empty string. Please, see this code:class Mock has a method called "getUrlAsString". This string ".WillOnce" means that we will call this method one time.
TEST(HtmlParser, NoData) {char *html;HttpFetchMock mock;HtmlParser parser(mock);EXPECT_CALL(mock, getUrlAsString("http://example.net")).WillOnce(Return(std::string(html)));}
This string "Return(std::string(html)" means that this method return empty string.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/CAPxskvFwF0f8invPV4_DLFWGTD5aD4mPvbB42Xz81w4OqXvbgg%40mail.gmail.com.
Now I see this text and my application is crashed:[==========] Running 1 test from 1 test case.[----------] Global test environment set-up.[----------] 1 test from HtmlParser[ RUN ] HtmlParser.OneLink../HtmlParser_gtests/main.cpp:28: FailureValue of: links.size()Actual: 0Expected: 1The program has unexpectedly finished.
#include <string>#include <vector>#include <gtest/gtest.h>#include <gmock/gmock.h>#include "HttpFetch.h"#include "HtmlParser.h"using ::testing::Return;class HttpFetchMock : public HttpFetch {public:MOCK_CONST_METHOD1( getUrlAsString, std::string( const std::string& ) );};
TEST(HtmlParser, OneLink) {char *html = "<html>""<head></head>""<body>""<a href='/index.html'>index.html</a>""</body>""</html>";HttpFetchMock mock;HtmlParser parser( mock );
EXPECT_CALL(mock, getUrlAsString("http://example.net")).WillOnce(Return(std::string(html)));std::vector<std::string> links = parser.getAllLinks("http://example.net");
EXPECT_EQ(1, links.size());EXPECT_STREQ("http://example.net/index.html", links[0].c_str());}//TEST(HtmlParser, NoData) {// char *html;// HttpFetchMock mock;// HtmlParser parser(mock);// EXPECT_CALL(mock, getUrlAsString("http://example.net"))// .WillOnce(Return(std::string("")));// std::vector<std::string> links = parser.getAllLinks("http://example.net");// EXPECT_EQ(0, links.size());//}
On Thu, May 29, 2014 at 12:48 PM, Ivan Enzhaev <8obse...@gmail.com> wrote:
Now I see this text and my application is crashed:[==========] Running 1 test from 1 test case.[----------] Global test environment set-up.[----------] 1 test from HtmlParser[ RUN ] HtmlParser.OneLink../HtmlParser_gtests/main.cpp:28: FailureValue of: links.size()Actual: 0Expected: 1The program has unexpectedly finished.