libcamera: utils: Add alignUp and alignDown functions

Add to libcamera utils library two functions to round up or down a
value to an alignment and add a test in test/utils.cpp for the two
new functions.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
Jacopo Mondi 2020-07-13 15:05:23 +02:00
parent 4383252d93
commit d405d1fd5e
3 changed files with 37 additions and 0 deletions

View file

@ -166,6 +166,17 @@ protected:
return TestFail;
}
/* utils::alignUp() and utils::alignDown() tests. */
if (utils::alignDown(6, 3) != 6 || utils::alignDown(7, 3) != 6) {
cerr << "utils::alignDown test failed" << endl;
return TestFail;
}
if (utils::alignUp(6, 3) != 6 || utils::alignUp(7, 3) != 9) {
cerr << "utils::alignUp test failed" << endl;
return TestFail;
}
return TestPass;
}
};