2018-03-13 10:36:20 +08:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Project _____ __ ____ _ _
|
|
|
|
* ( _ ) /__\ (_ _)_| |_ _| |_
|
|
|
|
* )(_)( /(__)\ )( (_ _)(_ _)
|
|
|
|
* (_____)(__)(__)(__) |_| |_|
|
|
|
|
*
|
|
|
|
*
|
2019-02-17 05:38:47 +08:00
|
|
|
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
|
2018-03-13 10:36:20 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "UnitTest.hpp"
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
namespace oatpp { namespace test {
|
|
|
|
|
2019-02-22 21:48:34 +08:00
|
|
|
void UnitTest::run(v_int32 times) {
|
2018-03-13 10:36:20 +08:00
|
|
|
|
2023-09-03 00:28:41 +08:00
|
|
|
OATPP_LOGI(TAG, "\033[1mSTART\033[0m...")
|
2018-03-13 10:36:20 +08:00
|
|
|
|
2024-04-23 07:41:04 +08:00
|
|
|
v_counter objectsCount = oatpp::Environment::getObjectsCount();
|
|
|
|
v_counter objectsCreated = oatpp::Environment::getObjectsCreated();
|
2021-10-13 14:34:10 +08:00
|
|
|
|
|
|
|
before();
|
2018-03-13 10:36:20 +08:00
|
|
|
|
2024-04-23 07:41:04 +08:00
|
|
|
v_int64 ticks = oatpp::Environment::getMicroTickCount();
|
2018-03-13 10:36:20 +08:00
|
|
|
|
|
|
|
for(v_int32 i = 0; i < times; i++){
|
2019-02-22 21:48:34 +08:00
|
|
|
onRun();
|
2018-03-13 10:36:20 +08:00
|
|
|
}
|
|
|
|
|
2024-04-23 07:41:04 +08:00
|
|
|
v_int64 millis = oatpp::Environment::getMicroTickCount() - ticks;
|
2021-10-13 14:34:10 +08:00
|
|
|
|
|
|
|
after();
|
2018-03-13 10:36:20 +08:00
|
|
|
|
2024-04-23 07:41:04 +08:00
|
|
|
v_counter leakingObjects = oatpp::Environment::getObjectsCount() - objectsCount;
|
|
|
|
v_counter objectsCreatedPerTest = oatpp::Environment::getObjectsCreated() - objectsCreated;
|
2018-03-13 10:36:20 +08:00
|
|
|
|
2019-02-22 21:48:34 +08:00
|
|
|
if(leakingObjects == 0){
|
2023-09-03 00:28:41 +08:00
|
|
|
OATPP_LOGI(TAG, "\033[1mFINISHED\033[0m - \033[1;32msuccess!\033[0m")
|
|
|
|
OATPP_LOGI(TAG, "\033[33m%ld(micro), %ld(objs)\033[0m\n", millis, objectsCreatedPerTest)
|
2018-03-13 10:36:20 +08:00
|
|
|
}else{
|
2019-02-22 21:48:34 +08:00
|
|
|
|
2023-09-03 00:28:41 +08:00
|
|
|
OATPP_LOGE(TAG, "\033[1mFINISHED\033[0m - \033[1;31mfailed\033[0m, leakingObjects = %ld", leakingObjects)
|
2019-03-23 09:06:39 +08:00
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2018-03-13 10:36:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}}
|