Search code examples
c++qtsignals-slotsgoogletest

How to use gtest for the functions that have no arguments but still do calculations?


AFAIK the basic document of gtest shows examples of functions with arguments.

I have to test functions which are slots to some signals. One of them does not have any parameters. Internally it fetches socket data, parses it using local variables, and then assigns values to class members.

What would be a way to test such a thing through gtest?


Solution

  • Separate it to two functions. One is core which takes arguments and the other is a wrapper that fetches socket data and pass it to the core. For example:

    result compute_core(data x);
    result compute_wrapper(){
        auto x=read_from_socket();
        return compute_core(x);
    }
    

    Now you can test compute_core as much as you want.