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

randombit / botan / 16399247596

19 Jul 2025 11:30PM UTC coverage: 90.635% (-0.07%) from 90.708%
16399247596

push

github

web-flow
Merge pull request #4998 from randombit/jack/fix-clang-tidy-readability-isolate-declaration

Enable and fix clang-tidy warning readability-isolate-declaration

99940 of 110266 relevant lines covered (90.64%)

12278552.1 hits per line

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

92.0
/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

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

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

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

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

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

49
         // TODO more tests
50

51
         return result;
1✔
52
      }
×
53

54
      static Result test_cnd_sub() {
1✔
55
         Result result("bigint_cnd_sub");
1✔
56

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

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

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

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

69
         return result;
1✔
70
      }
×
71

72
      static Result test_cnd_abs() {
1✔
73
         Result result("bigint_cnd_abs");
1✔
74

75
         const Botan::word max = Botan::WordInfo<Botan::word>::max;
1✔
76

77
         Botan::word x1 = max;
1✔
78
         Botan::bigint_cnd_abs<Botan::word>(1, &x1, 1);
1✔
79
         result.test_int_eq(x1, 1, "Abs");
1✔
80

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

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

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

93
         Botan::word x2[2] = {max, max};
1✔
94

95
         Botan::bigint_cnd_abs<Botan::word>(1, x2, 2);
1✔
96
         result.test_int_eq(x2[0], 1, "Abs");
1✔
97
         result.test_int_eq(x2[1], 0, "Abs");
1✔
98

99
         return result;
1✔
100
      }
×
101

102
      static Result test_cnd_swap() {
1✔
103
         Result result("bigint_cnd_swap");
1✔
104

105
         // null with zero length is ok
106
         Botan::bigint_cnd_swap<Botan::word>(0, nullptr, nullptr, 0);
1✔
107
         Botan::bigint_cnd_swap<Botan::word>(1, nullptr, nullptr, 0);
1✔
108

109
         Botan::word x1 = 5;
1✔
110
         Botan::word y1 = 9;
1✔
111

112
         Botan::bigint_cnd_swap<Botan::word>(0, &x1, &y1, 1);
1✔
113
         result.test_int_eq(x1, 5, "No swap");
1✔
114
         Botan::bigint_cnd_swap<Botan::word>(1, &x1, &y1, 1);
1✔
115
         result.test_int_eq(x1, 9, "Swap");
1✔
116

117
         Botan::word x5[5] = {0, 1, 2, 3, 4};
1✔
118
         Botan::word y5[5] = {3, 2, 1, 0, 9};
1✔
119

120
         // Should only modify first four
121
         Botan::bigint_cnd_swap<Botan::word>(1, x5, y5, 4);
1✔
122

123
         for(size_t i = 0; i != 4; ++i) {
5✔
124
            result.test_int_eq(x5[i], 3 - i, "Swap x5");
4✔
125
         }
126
         result.test_int_eq(x5[4], 4, "Not touched");
1✔
127

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

133
         return result;
1✔
134
      }
×
135
};
136

137
BOTAN_REGISTER_TEST("math", "mp_unit", MP_Unit_Tests);
138

139
#endif
140

141
}  // namespace
142

143
}  // 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

© 2026 Coveralls, Inc