1 //===-- sanitizer_symbolizer_test.cc --------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Tests for sanitizer_symbolizer.h and sanitizer_symbolizer_internal.h
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "sanitizer_common/sanitizer_allocator_internal.h"
15 #include "sanitizer_common/sanitizer_symbolizer_internal.h"
16 #include "gtest/gtest.h"
17 
18 namespace __sanitizer {
19 
TEST(Symbolizer,ExtractToken)20 TEST(Symbolizer, ExtractToken) {
21   char *token;
22   const char *rest;
23 
24   rest = ExtractToken("a;b;c", ";", &token);
25   EXPECT_STREQ("a", token);
26   EXPECT_STREQ("b;c", rest);
27   InternalFree(token);
28 
29   rest = ExtractToken("aaa-bbb.ccc", ";.-*", &token);
30   EXPECT_STREQ("aaa", token);
31   EXPECT_STREQ("bbb.ccc", rest);
32   InternalFree(token);
33 }
34 
TEST(Symbolizer,ExtractInt)35 TEST(Symbolizer, ExtractInt) {
36   int token;
37   const char *rest = ExtractInt("123,456;789", ";,", &token);
38   EXPECT_EQ(123, token);
39   EXPECT_STREQ("456;789", rest);
40 }
41 
TEST(Symbolizer,ExtractUptr)42 TEST(Symbolizer, ExtractUptr) {
43   uptr token;
44   const char *rest = ExtractUptr("123,456;789", ";,", &token);
45   EXPECT_EQ(123U, token);
46   EXPECT_STREQ("456;789", rest);
47 }
48 
TEST(Symbolizer,ExtractTokenUpToDelimiter)49 TEST(Symbolizer, ExtractTokenUpToDelimiter) {
50   char *token;
51   const char *rest =
52       ExtractTokenUpToDelimiter("aaa-+-bbb-+-ccc", "-+-", &token);
53   EXPECT_STREQ("aaa", token);
54   EXPECT_STREQ("bbb-+-ccc", rest);
55   InternalFree(token);
56 }
57 
58 }  // namespace __sanitizer
59