janitor

janitor
git clone https://git.prime8.dev/janitor.git
Log | Files | Refs | README | LICENSE

test-log.cc (2226B)


      1 /**
      2  * Copyright      2022  Xiaomi Corporation (authors: Fangjun Kuang)
      3  *
      4  * See LICENSE for clarification regarding multiple authors
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *     http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  */
     18 
     19 #if KNF_ENABLE_CHECK
     20 #include "gtest/gtest.h"
     21 #include "kaldi-native-fbank/csrc/log.h"
     22 
     23 namespace knf {
     24 
     25 TEST(Log, TestLog) {
     26   KNF_LOG(TRACE) << "this is a trace message";
     27   KNF_LOG(DEBUG) << "this is a debug message";
     28   KNF_LOG(INFO) << "this is an info message";
     29   KNF_LOG(WARNING) << "this is a warning message";
     30   KNF_LOG(ERROR) << "this is an error message";
     31 
     32   ASSERT_THROW(KNF_LOG(FATAL) << "This will crash the program",
     33                std::runtime_error);
     34 
     35   // For debug build
     36 
     37   KNF_DLOG(TRACE) << "this is a trace message for debug build";
     38   KNF_DLOG(DEBUG) << "this is a trace message for debug build";
     39   KNF_DLOG(INFO) << "this is a trace message for debug build";
     40   KNF_DLOG(ERROR) << "this is an error message for debug build";
     41   KNF_DLOG(WARNING) << "this is a trace message for debug build";
     42 
     43 #if !defined(NDEBUG)
     44   ASSERT_THROW(KNF_DLOG(FATAL) << "this is a trace message for debug build",
     45                std::runtime_error);
     46 #endif
     47 }
     48 
     49 TEST(Log, TestCheck) {
     50   KNF_CHECK_EQ(1, 1) << "ok";
     51   KNF_CHECK_LE(1, 3) << "ok";
     52   KNF_CHECK_LT(1, 2) << "ok";
     53   KNF_CHECK_GT(2, 1) << "ok";
     54   KNF_CHECK_GE(2, 1) << "ok";
     55 
     56   ASSERT_THROW(KNF_CHECK_EQ(2, 1) << "bad things happened", std::runtime_error);
     57 
     58   // for debug build
     59   KNF_DCHECK_EQ(1, 1) << "ok";
     60   KNF_DCHECK_LE(1, 3) << "ok";
     61   KNF_DCHECK_LT(1, 2) << "ok";
     62   KNF_DCHECK_GT(2, 1) << "ok";
     63   KNF_DCHECK_GE(2, 1) << "ok";
     64 
     65 #if !defined(NDEBUG)
     66   ASSERT_THROW(KNF_CHECK_EQ(2, 1) << "bad things happened", std::runtime_error);
     67 #endif
     68 }
     69 
     70 }  // namespace knf
     71 #endif