• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.68
/src/tests/test_mp.cpp
1
/*
2
* (C) 2016 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_BIGINT_MP)
10
   #include <botan/internal/mp_core.h>
11
#endif
12

13
namespace Botan_Tests {
14

15
namespace {
16

17
#if defined(BOTAN_HAS_BIGINT_MP)
18

19
class MP_Unit_Tests final : public Test {
×
20
   public:
21
      std::vector<Test::Result> run() override {
1✔
22
         std::vector<Test::Result> results;
1✔
23

24
         results.push_back(test_cnd_swap());
2✔
25
         results.push_back(test_cnd_add());
2✔
26
         results.push_back(test_cnd_sub());
2✔
27
         results.push_back(test_cnd_abs());
2✔
28

29
         return results;
1✔
30
      }
×
31

32
   private:
33
      static Result test_cnd_add() {
1✔
34
         Result result("bigint_cnd_add");
1✔
35
         result.start_timer();
1✔
36

37
         const Botan::word max = ~static_cast<Botan::word>(0);
1✔
38

39
         Botan::word a = 2;
1✔
40
         Botan::word c = Botan::bigint_cnd_add<Botan::word>(0, &a, &max, 1);
1✔
41

42
         result.test_int_eq(a, 2, "No op");
1✔
43
         result.test_int_eq(c, 0, "No op");
1✔
44

45
         c = Botan::bigint_cnd_add<Botan::word>(1, &a, &max, 1);
1✔
46

47
         result.test_int_eq(a, 1, "Add");
1✔
48
         result.test_int_eq(c, 1, "Carry");
1✔
49

50
         // TODO more tests
51
         result.end_timer();
1✔
52
         return result;
1✔
53
      }
×
54

55
      static Result test_cnd_sub() {
1✔
56
         Result result("bigint_cnd_sub");
1✔
57
         result.start_timer();
1✔
58

59
         Botan::word a = 2;
1✔
60
         Botan::word b = 3;
1✔
61
         Botan::word c = Botan::bigint_cnd_sub<Botan::word>(0, &a, &b, 1);
1✔
62

63
         result.test_int_eq(a, 2, "No op");
1✔
64
         result.test_int_eq(c, 0, "No op");
1✔
65

66
         c = Botan::bigint_cnd_sub<Botan::word>(1, &a, &b, 1);
1✔
67

68
         result.test_int_eq(a, ~static_cast<Botan::word>(0), "Sub");
1✔
69
         result.test_int_eq(c, 1, "Borrow");
1✔
70

71
         result.end_timer();
1✔
72
         return result;
1✔
73
      }
×
74

75
      static Result test_cnd_abs() {
1✔
76
         Result result("bigint_cnd_abs");
1✔
77
         result.start_timer();
1✔
78

79
         const Botan::word max = Botan::WordInfo<Botan::word>::max;
1✔
80

81
         Botan::word x1 = max;
1✔
82
         Botan::bigint_cnd_abs<Botan::word>(1, &x1, 1);
1✔
83
         result.test_int_eq(x1, 1, "Abs");
1✔
84

85
         x1 = 0;
1✔
86
         Botan::bigint_cnd_abs<Botan::word>(1, &x1, 1);
1✔
87
         result.test_int_eq(x1, 0, "Abs");
1✔
88

89
         x1 = 1;
1✔
90
         Botan::bigint_cnd_abs<Botan::word>(1, &x1, 1);
1✔
91
         result.test_int_eq(x1, max, "Abs");
1✔
92

93
         x1 = 1;
1✔
94
         Botan::bigint_cnd_abs<Botan::word>(0, &x1, 1);
1✔
95
         result.test_int_eq(x1, 1, "No change");
1✔
96

97
         Botan::word x2[2] = {max, max};
1✔
98

99
         Botan::bigint_cnd_abs<Botan::word>(1, x2, 2);
1✔
100
         result.test_int_eq(x2[0], 1, "Abs");
1✔
101
         result.test_int_eq(x2[1], 0, "Abs");
1✔
102

103
         result.end_timer();
1✔
104
         return result;
1✔
105
      }
×
106

107
      static Result test_cnd_swap() {
1✔
108
         Result result("bigint_cnd_swap");
1✔
109
         result.start_timer();
1✔
110

111
         // null with zero length is ok
112
         Botan::bigint_cnd_swap<Botan::word>(0, nullptr, nullptr, 0);
1✔
113
         Botan::bigint_cnd_swap<Botan::word>(1, nullptr, nullptr, 0);
1✔
114

115
         Botan::word x1 = 5, y1 = 9;
1✔
116

117
         Botan::bigint_cnd_swap<Botan::word>(0, &x1, &y1, 1);
1✔
118
         result.test_int_eq(x1, 5, "No swap");
1✔
119
         Botan::bigint_cnd_swap<Botan::word>(1, &x1, &y1, 1);
1✔
120
         result.test_int_eq(x1, 9, "Swap");
1✔
121

122
         Botan::word x5[5] = {0, 1, 2, 3, 4};
1✔
123
         Botan::word y5[5] = {3, 2, 1, 0, 9};
1✔
124

125
         // Should only modify first four
126
         Botan::bigint_cnd_swap<Botan::word>(1, x5, y5, 4);
1✔
127

128
         for(size_t i = 0; i != 4; ++i) {
5✔
129
            result.test_int_eq(x5[i], 3 - i, "Swap x5");
4✔
130
         }
131
         result.test_int_eq(x5[4], 4, "Not touched");
1✔
132

133
         for(size_t i = 0; i != 4; ++i) {
5✔
134
            result.test_int_eq(y5[i], i, "Swap y5");
4✔
135
         }
136
         result.test_int_eq(y5[4], 9, "Not touched");
1✔
137

138
         result.end_timer();
1✔
139
         return result;
1✔
140
      }
×
141
};
142

143
BOTAN_REGISTER_TEST("math", "mp_unit", MP_Unit_Tests);
144

145
#endif
146

147
}  // namespace
148

149
}  // namespace Botan_Tests
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc