about summary refs log blame commit diff stats
path: root/022div.cc
blob: 15ed89d83d847d4e8b35ce9c3ffe5655f58bc82f (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                            
                     



















                                                                                       
                     






                                       
//: helper for division operations: sign-extend EAX into EDX

:(before "End Initialize Op Names")
put_new(Name, "99", "sign-extend EAX into EDX (cdq)");

:(code)
void test_cdq() {
  Reg[EAX].i = 10;
  run(
      "== code 0x1\n"
      "99\n"
  );
  CHECK_TRACE_CONTENTS(
      "run: sign-extend EAX into EDX\n"
      "run: EDX is now 0x00000000\n"
  );
}

:(before "End Single-Byte Opcodes")
case 0x99: {  // sign-extend EAX into EDX
  trace(Callstack_depth+1, "run") << "sign-extend EAX into EDX" << end();
  Reg[EDX].i = (Reg[EAX].i < 0) ? -1 : 0;
  trace(Callstack_depth+1, "run") << "EDX is now 0x" << HEXWORD << Reg[EDX].u << end();
  break;
}

:(code)
void test_cdq_negative() {
  Reg[EAX].i = -10;
  run(
      "== code 0x1\n"
      "99\n"
  );
  CHECK_TRACE_CONTENTS(
      "run: sign-extend EAX into EDX\n"
      "run: EDX is now 0xffffffff\n"
  );
}
ommit/tests/unittests/test_plugins_disco.c?id=9945246a648998e374c0c3a5ac56cdffc63ef13a'>9945246a ^
a2726b6a ^
9945246a ^












a2726b6a ^
9945246a ^





a2726b6a ^
9945246a ^










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

                   

                   




                          
                                          

                  
                                           







                                                 
                                   



                                                           
                                           
                                                 
                                   






                                                         
                                      



                                                           
                                           











                                                 
                                        







                                                        
                                           

                                                 




                                                                                         





                          
                                            




                                                         
                                           






                                                 
                                     





                                                     
                                           












                                                 
                                                                  





                                             
                                           










                                                 
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>

#include "plugins/disco.h"

void
returns_empty_list_when_none(void** state)
{
    disco_close();
    GList* features = disco_get_features();

    assert_int_equal(g_list_length(features), 0);

    g_list_free(features);
    disco_close();
}

void
returns_added_feature(void** state)
{
    disco_close();
    disco_add_feature("my_plugin", "some:feature:example");

    GList* features = disco_get_features();
    assert_int_equal(g_list_length(features), 1);
    char* feature = features->data;
    assert_string_equal(feature, "some:feature:example");

    g_list_free(features);
    disco_close();
}

void
resets_features_on_close(void** state)
{
    disco_close();
    disco_add_feature("my_plugin", "some:feature:example");

    GList* features = disco_get_features();
    assert_int_equal(g_list_length(features), 1);
    g_list_free(features);

    disco_close();
    features = disco_get_features();
    assert_int_equal(g_list_length(features), 0);

    g_list_free(features);
    disco_close();
}

void
returns_all_added_features(void** state)
{
    disco_close();
    disco_add_feature("first_plugin", "first:feature");
    disco_add_feature("first_plugin", "second:feature");
    disco_add_feature("second_plugin", "third:feature");
    disco_add_feature("third_plugin", "fourth:feature");
    disco_add_feature("third_plugin", "fifth:feature");

    GList* features = disco_get_features();

    assert_int_equal(g_list_length(features), 5);
    assert_true(g_list_find_custom(features, "first:feature", (GCompareFunc)g_strcmp0));
    assert_true(g_list_find_custom(features, "second:feature", (GCompareFunc)g_strcmp0));
    assert_true(g_list_find_custom(features, "third:feature", (GCompareFunc)g_strcmp0));
    assert_true(g_list_find_custom(features, "fourth:feature", (GCompareFunc)g_strcmp0));
    assert_true(g_list_find_custom(features, "fifth:feature", (GCompareFunc)g_strcmp0));

    g_list_free(features);
    disco_close();
}

void
does_not_add_duplicate_feature(void** state)
{
    disco_close();
    disco_add_feature("my_plugin", "my:feature");
    disco_add_feature("some_other_plugin", "my:feature");

    GList* features = disco_get_features();
    assert_int_equal(g_list_length(features), 1);

    g_list_free(features);
    disco_close();
}

void
removes_plugin_features(void** state)
{
    disco_close();
    disco_add_feature("plugin1", "plugin1:feature1");
    disco_add_feature("plugin1", "plugin1:feature2");
    disco_add_feature("plugin2", "plugin2:feature1");

    GList* features = disco_get_features();
    assert_int_equal(g_list_length(features), 3);
    g_list_free(features);

    disco_remove_features("plugin1");

    features = disco_get_features();
    assert_int_equal(g_list_length(features), 1);

    g_list_free(features);
    disco_close();
}

void
does_not_remove_feature_when_more_than_one_reference(void** state)
{
    disco_close();
    disco_add_feature("plugin1", "feature1");
    disco_add_feature("plugin1", "feature2");
    disco_add_feature("plugin2", "feature1");

    GList* features = disco_get_features();
    assert_int_equal(g_list_length(features), 2);
    g_list_free(features);

    disco_remove_features("plugin1");

    features = disco_get_features();
    assert_int_equal(g_list_length(features), 1);

    g_list_free(features);
    disco_close();
}