mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
test/libutil: Add OBSERVE_STRING macro
Makes string callback easier to pass, without mistakes.
This commit is contained in:
parent
876e70bc9a
commit
a512f4eebc
4 changed files with 33 additions and 20 deletions
9
tests/unit/libutil-support/tests/string_callback.cc
Normal file
9
tests/unit/libutil-support/tests/string_callback.cc
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "string_callback.hh"
|
||||
|
||||
namespace nix::testing {
|
||||
|
||||
void observe_string_cb(const char * start, unsigned int n, std::string * user_data) {
|
||||
*user_data = std::string(start);
|
||||
}
|
||||
|
||||
}
|
12
tests/unit/libutil-support/tests/string_callback.hh
Normal file
12
tests/unit/libutil-support/tests/string_callback.hh
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace nix::testing {
|
||||
|
||||
void observe_string_cb(const char * start, unsigned int n, std::string * user_data);
|
||||
inline void * observe_string_cb_data(std::string & out) {
|
||||
return (void *) &out;
|
||||
};
|
||||
#define OBSERVE_STRING(str) (void *)nix::testing::observe_string_cb, nix::testing::observe_string_cb_data(str)
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue