How to create a unit test?
Nikolaos Chatzikonstantinou
nchatz314 at gmail.com
Sun Oct 23 15:54:51 CEST 2022
On Sun, Oct 23, 2022 at 9:40 AM Brad House <brad at brad-house.com> wrote:
> On 10/23/22 5:41 AM, Nikolaos Chatzikonstantinou via c-ares wrote:
> > How can I create a unit test on git HEAD? Suppose for example I would
> > like to write tests for the functions under ./src/lib/ares_android.c.
> c-ares uses gmock :
> https://google.github.io/googletest/gmock_for_dummies.html
>
> So you'd have to use that framework to write unit tests.
>
> That said, your example of src/lib/ares_android.c would be easier said
> than done as a unit test for android would actually have to run on an
> android platform, but typically when compiling for android, you are
> cross compiling and not compiling and testing natively.
I wanted to write a unit test for ./src/lib/ares_strsplit.c to show a
bug that I wrote a patch for. I tried to enter the following in
./test/ares-test-internal.cc:
#include "ares_strsplit.h"
TEST_F(LibraryTest, Strsplit) {
size_t n;
char **p = ares_strsplit("example.com, example.co", ", ", 1, &n);
EXPECT_EQ(n, 2);
ares_strsplit_free(p, n);
}
Then I use mkdir build && ./buildconf && cd build && ../configure &&
make. However when I compile the project, I get an 'undefined
reference' linker error on ares_strsplit.
Regards,
Nikolaos Chatzikonstantinou
More information about the c-ares
mailing list