diff --git a/test/integration/capture_keys.toml b/test/integration/capture_keys.toml index 4dd1a0b..762dbab 100644 --- a/test/integration/capture_keys.toml +++ b/test/integration/capture_keys.toml @@ -1,7 +1,7 @@ # This file contains tests for core key-capture features at the top, followed # by basic tests for each container type which supports key capture. -includes = ["map"] +includes = ["map","sys/mman.h"] definitions = ''' struct MapHolder { std::map captureMyKeys; @@ -13,6 +13,33 @@ enum class MyEnum { Two = 2, Three = 3, }; + +struct KeyObj { + int n; + auto operator<=>(const KeyObj &) const = default; +}; +template +class FixedAllocator { + public: + using value_type = T; + T* allocate(std::size_t n) { + uintptr_t loc = base_ + num_*0x1000; + num_++; + return (T*)mmap((void*)loc, + n, + PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, + -1, + 0); + } + void deallocate(T*, std::size_t) noexcept { + // cba + } + + private: + uintptr_t base_ = 0x300000; + size_t num_ = 0; +}; ''' [cases] [cases.int] @@ -118,6 +145,46 @@ enum class MyEnum { ] }]''' + [cases.object] + oid_skip = "Requires TreeBuilderV2" + param_types = ["const std::map, FixedAllocator>>&"] + # We're going to record the addresses of these objects, so we use a custom + # allocator based on mmap to get them at a known location in memory + setup = ''' + std::map, FixedAllocator>> m; + m.insert({KeyObj{1}, 1}); + m.insert({KeyObj{2}, 2}); + return m; + ''' + config_suffix = ''' + [[codegen.capture_keys]] + top_level = true + ''' + expect_json_v2 = '''[{ + "name": "a0", + "typePath": ["a0"], + "members": [ + { + "name": "[]", + "typePath": ["a0","[]"], + "data": "0x300020", + "members": [ + {"name": "key", "typePath": ["a0","[]","key"]}, + {"name": "value", "typePath": ["a0","[]","value"]} + ] + }, + { + "name": "[]", + "typePath": ["a0","[]"], + "data": "0x301020", + "members": [ + {"name": "key", "typePath": ["a0","[]","key"]}, + {"name": "value", "typePath": ["a0","[]","value"]} + ] + } + ] + }]''' + [cases.multi_level] oid_skip = "Requires TreeBuilderV2" param_types = ["const std::map>>&"]