Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 30 04:20
    billcxx closed #315
  • Nov 30 04:20
    billcxx commented #315
  • Nov 29 19:17
    Snaipe commented #315
  • Nov 29 19:06
    Snaipe commented #315
  • Nov 29 18:40
    billcxx opened #315
  • Nov 26 17:28
    Snaipe commented #314
  • Nov 22 17:11
    Bensuperpc edited #314
  • Nov 22 17:09
    Bensuperpc edited #314
  • Nov 22 17:08
    Bensuperpc opened #314
  • Nov 21 00:40
    karlvignon commented #223
  • Nov 13 21:29
    kugel- commented #172
  • Nov 13 20:49
    Snaipe commented #312
  • Nov 13 20:29
    Snaipe labeled #313
  • Nov 13 20:29
    Snaipe labeled #313
  • Nov 13 20:29
    Snaipe labeled #313
  • Nov 13 20:29
    Snaipe opened #313
  • Nov 13 20:26
    Snaipe commented #172
  • Nov 13 15:12
    kugel- commented #172
  • Nov 11 17:41
    jonathanturcotte commented #312
  • Nov 06 16:25
    jonathanturcotte commented #312
Franklin Mathieu
@Snaipe
@DoumanAsh mmk_when takes an expression that must call your mocked function with the parameter (or matchers) you want
e.g. if you're mocking malloc, and want to describe the behaviour of the mock when called with 4, you'd do mmk_when(malloc(4), ...)
(do mind that for some standard functions like malloc or memset the CallExpr can be optimized away because the compiler thinks that it has no side effects)
Douman
@DoumanAsh
@Snaipe it is just after i made test i tried to change expression, but it seems it works as usual... even though test itself works as usual. For example i tried to mmk_when(GetClipboardData(mmk_eq(UINT, format))) - format is variable. Test works, then i tried to change it like format + 1 it works too. But when i use mmk_verify(GetClipboardData(mmk_eq(UINT, format + 1)) it finds error
Franklin Mathieu
@Snaipe
do you perhaps have a self contained example with the expected vs actual result?
Douman
@DoumanAsh
Not right now, i'll push my code and will link it
Douman
@DoumanAsh
Here is repo https://github.com/DoumanAsh/lazy-winapi.c - It relies on WinAPI so it works only on windows... Do you use Windows? If not maybe i could try to make some more simple example. You can build it with Cmake UNIT_TESTING option and then build unit tests with make. In result there should be ut.exe, but these tests are stable only with -j1 :(
If i try to change mmk_eq(UINT, format) over https://github.com/DoumanAsh/lazy-winapi.c/blob/master/test/clipboard_mock.c#L38 with a different value of format, test will pass. But if i do the same over line https://github.com/DoumanAsh/lazy-winapi.c/blob/master/test/clipboard_mock.c#L42 then it fails
Not sure if i got it right though
Franklin Mathieu
@Snaipe
If you're changing the parameter in mmk_verify to format + 1, you also need to make sure that GetClipboardData gets passed format + 1
in essence mmk_verify, well, verifies that GetClipboardData gets called with the right parameters, so you'd need to change format to format + 1 on lines 38, 40, and 42
(in clipboard_mock.c)
Douman
@DoumanAsh
But what will happen if i wouldn't pass it to GetCLipboardData? As of now test works ok
also i changed mmk_when, not mmk_verify
I assumed if i would change mmk_when then mmk_verify would fail, but it works
Franklin Mathieu
@Snaipe
both are actually independent
mmk_when specifies what happens at runtime when the function gets called
mmk_verify checks whether the function was called the way you wanted
they can work together or independently
Douman
@DoumanAsh
hm... but i don't exactly get mmk_when then.. i expected that it would invoke mock only when i pass format +1 to mock, but it gets invoked anyway
is there any purpose in specifying condition?
Franklin Mathieu
@Snaipe
by condition do you mean mmk_eq(UINT, format)rather than just format?
however mmk_eq is only relevant when you use other matchers
Douman
@DoumanAsh
yes, i meant mmk_eq(UINT, format) and by format + 1 i meant mmk_eq(UINT, format + 1)
Franklin Mathieu
@Snaipe
if so, yes, there is in fact no difference in this case between the two syntaxes
Douman
@DoumanAsh
and i'm confused because it makes no difference to my mock having either mmk_eq(UINT, format) or mmk_eq(UINT, format + 1)
Franklin Mathieu
@Snaipe
for instance mmk_when(func(1, mmk_le(int, 2)), .then_return = 0) is illegal because you can't mix matchers and non-matchers, so you need to use mmk_eq(int, 1) in this case
and in your case, it doesn't make any difference because by default the mock returns a zero-ish value for unspecified parameters
so, in your case, it always returns NULL
Douman
@DoumanAsh
aha... so that's why
Franklin Mathieu
@Snaipe
if you need it to return a valid clipboard HANDLE for certain values, I would probably call GetClipboardData before creating the mock, and do something like mmk_when(GetClipboardData(42), .then_return = the_handle)
Douman
@DoumanAsh
Well, i'm testing negative paths of my functions. For positive cases i use simple tests without mocks as there is no need
Btw is it indented that without any mmk_when my test would crash, if by default all mocks return NULL ?
Franklin Mathieu
@Snaipe
sounds like a bug
Douman
@DoumanAsh
I get this assertion failure E:/Downloads/Git/c_plus_plus/lazy-winapi/build/3pp/src/Mimick/src/matcher.c:51: Assertion failed: v__ != NULL
when i jsut remove any mmk_when
Franklin Mathieu
@Snaipe
no mmk_when and 1 mmk_verify, right?
I think mmk_when does some initialization that should have been mirrored in mmk_verify
Douman
@DoumanAsh
yes
hmm... i see, but i suppose it would be better for user to specify mmk_when regardless of default return value. Just this assertion makes no sense :)
Anyway, mimick is great :) though it is impossible to read compile errors/warnings :D
Franklin Mathieu
@Snaipe
If you're using a GNU compiler, you can reduce the verbosity of compile errors with -isystem=/path/to/mimick/include
Douman
@DoumanAsh
cool, thanks for a tip
Franklin Mathieu
@Snaipe
If you're using a GNU compiler, you can reduce the verbosity of compile errors with -isystem=/path/to/mimick/include
unfortunately I don't think there's a similar trigger for MSVC :/
(also sorry if my messages appear late and/or out of order, I'm on a train)
Douman
@DoumanAsh
well i prefer gcc as MSVC is just bloatware so iti s fine :)
thanks for help, again. Good luck you on your way.
Franklin Mathieu
@Snaipe
No problem, it's the least I can do.
Yuriy Yarosh
@yuriy-yarosh

o/
cr_malloc returns NULL on MacOS, for unknown reason.

Test(uri_tests, emptySchemaShouldBeParsed) {

    URI* testURI = cr_malloc(sizeof(URI));
    cr_log_warn("%u", (uint) sizeof(URI));
    cr_log_error("%u", (uint) testURI);
    cr_assert_not_null(testURI, "URI should be allocated");
...

leads to

[WARN] 88
[ERR ] 0
[----] ~/src/.../Tests/uri_test.c:12: Assertion failed: URI should be allocated
[FAIL] uri_tests::emptySchemaShouldBeParsed: (0.00s)
[====] Synthesis: Tested: 1 | Passing: 0 | Failing: 1 | Crashing: 0