Add tests for RTable using r2 commands

This commit is contained in:
pancake 2020-09-24 00:32:38 +02:00 committed by pancake
parent e13753e6d0
commit 7c76d85031
3 changed files with 147 additions and 7 deletions

View File

@ -46,7 +46,7 @@ typedef struct {
RList *cols;
int totalCols;
bool showHeader;
bool showSimple;
bool showFancy;
bool showJSON;
bool showCSV;
bool showSum;

View File

@ -403,10 +403,10 @@ R_API char *r_table_tostring(RTable *t) {
free (s);
return q;
}
if (t->showSimple) {
return r_table_tosimplestring (t);
if (t->showFancy) {
return r_table_tofancystring (t);
}
return r_table_tofancystring (t);
return r_table_tosimplestring (t);
}
R_API char *r_table_tosimplestring(RTable *t) {
@ -553,8 +553,10 @@ R_API void r_table_filter(RTable *t, int nth, int op, const char *un) {
if (page < 1) {
page = 1;
}
lrow = page_items * (page - 1);
uv = page_items * (page);
if (!ST32_MUL_OVFCHK (page, page_items)) {
lrow = page_items * (page - 1);
uv = page_items * (page);
}
}
size_t nrow = 0;
r_list_foreach_safe (t->rows, iter, iter2, row) {
@ -905,8 +907,10 @@ static bool __table_special(RTable *t, const char *columnName) {
}
if (!strcmp (columnName, ":quiet")) {
t->showHeader = true;
} else if (!strcmp (columnName, ":fancy")) {
t->showFancy = true;
} else if (!strcmp (columnName, ":simple")) {
t->showSimple = true;
t->showFancy = false;
} else if (!strcmp (columnName, ":csv")) {
t->showCSV = true;
} else if (!strcmp (columnName, ":json")) {

136
test/db/cmd/tables Normal file
View File

@ -0,0 +1,136 @@
NAME=tables sum
FILE=bins/elf/analysis/elf-virtualtable
CMDS=<<EOF
f, size/sum
EOF
EXPECT=<<EOF
size
----
16.8K
EOF
RUN
NAME=tables sort
FILE=bins/elf/analysis/elf-virtualtable
CMDS=<<EOF
f, size/cols,size/sort,size/uniq
EOF
EXPECT=<<EOF
size
----
0
1
2
3
4
6
8
9
13
16
17
21
23
24
26
28
32
36
42
43
52
56
62
64
66
68
80
88
96
101
104
124
158
176
203
240
256
268
272
432
448
464
497
512
540
978
1160
1255
2424
4132
EOF
RUN
NAME=tables csv
FILE=bins/elf/analysis/elf-virtualtable
CMDS=<<EOF
f, size/ne/0,addr/ne/0x00000000,/head/10,:csv~:..20
f, space/eq/relocs,addr/cols/name,/head/3,:json~{}
f, /head/10,/tail/4,space/cols/name
f, /page/2/10,sort/cols/space/size/name,size/sort/inc,:fancy
EOF
EXPECT=<<EOF
addr,size,space,name
0x00400000,4132,segments,segment.LOAD0
0x00400000,64,segments,segment.ehdr
0x00400040,448,segments,segment.PHDR
0x00400200,28,sections,section..interp
0x00400200,28,segments,segment.INTERP
0x0040021c,32,sections,section..note.ABI_tag
0x0040021c,68,segments,segment.NOTE
0x0040023c,36,sections,section..note.gnu.build_id
0x00400260,56,sections,section..gnu.hash
0x00400298,432,sections,section..dynsym
[
{
"addr": 6296136,
"name": "reloc.__gmon_start"
},
{
"addr": 6296168,
"name": "reloc.std::ostream::operator___int"
},
{
"addr": 6296176,
"name": "reloc.operator_delete_void"
}
]
space name
---------------------
segments segment.GNU_STACK
symbols.sections sym..comment
imports loc.imp.__gmon_start
imports loc.imp._Jv_RegisterClasses
imports loc.imp._ITM_deregisterTMCloneTable
.----------------------------------------------------------------------------------------------------.
| space | size | name |
)----------------------------------------------------------------------------------------------------(
| classes | 1 | class.std::ostream |
| classes | 1 | class.std::ios_base::Init |
| classes | 1 | class.std::basic_ostream_char__std::char_traits_char_____std::operator____std |
| classes | 1 | class.std::basic_ostream_char__std::char_traits_char_____std::endl_char__std |
| classes | 1 | class.B |
| classes | 1 | class.A |
| classes | 1 | class.C |
| imports | 16 | loc.imp._ITM_registerTMCloneTable |
| imports | 16 | loc.imp._ITM_deregisterTMCloneTable |
| segments | 64 | segment.ehdr |
| segments | 4132 | segment.LOAD0 |
`----------------------------------------------------------------------------------------------------'
EOF
RUN