1 /*  $Id: psg_cache_base.cpp 597217 2019-11-18 22:34:40Z saprykin $
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *               National Center for Biotechnology Information
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government have not placed any restriction on its use or reproduction.
13 *
14 *  Although all reasonable efforts have been taken to ensure the accuracy
15 *  and reliability of the software and data, the NLM and the U.S.
16 *  Government do not and cannot warrant the performance or results that
17 *  may be obtained by using this software or data. The NLM and the U.S.
18 *  Government disclaim all warranties, express or implied, including
19 *  warranties of performance, merchantability or fitness for any particular
20 *  purpose.
21 *
22 *  Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author:  Dmitrii Saprykin, NCBI
27 *
28 * File Description:
29 *   Unit test suite to check basic functionality for CPubseqGatewayCache
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 
36 #include <objtools/pubseq_gateway/cache/psg_cache.hpp>
37 
38 #include <gtest/gtest.h>
39 
40 BEGIN_IDBLOB_SCOPE
41 
operator ==(const CPubseqGatewayCache::TRuntimeError a,const CPubseqGatewayCache::TRuntimeError b)42 bool operator==(const CPubseqGatewayCache::TRuntimeError a, const CPubseqGatewayCache::TRuntimeError b)
43 {
44     return a.message == b.message;
45 }
46 
operator <<(std::ostream & os,const CPubseqGatewayCache::TRuntimeError & error)47 std::ostream& operator<<(std::ostream& os, const CPubseqGatewayCache::TRuntimeError& error) {
48   return os << "'" << error.message << "'";  // whatever needed to print bar to os
49 }
50 
51 END_IDBLOB_SCOPE
52 
53 BEGIN_SCOPE()
54 USING_NCBI_SCOPE;
55 USING_IDBLOB_SCOPE;
56 
TEST(PubseqGatewayCacheRuntimeErrors,EmptyOnStart)57 TEST(PubseqGatewayCacheRuntimeErrors, EmptyOnStart) {
58     CPubseqGatewayCache cache("", "", "");
59     EXPECT_TRUE(cache.GetErrors().empty());
60 }
61 
TEST(PubseqGatewayCacheRuntimeErrors,WrongFileNames)62 TEST(PubseqGatewayCacheRuntimeErrors, WrongFileNames) {
63     CPubseqGatewayCache::TRuntimeErrorList expected_error_list{
64         CPubseqGatewayCache::TRuntimeError("Failed to open 'wrong si2sci' cache: No such file or directory: "
65             "No such file or directory, si2csi cache will not be used."),
66         CPubseqGatewayCache::TRuntimeError("Failed to open '/really_wrong_blob_prop' cache: "
67             "List of satellites is empty: Successful return: 0, blob prop cache will not be used."),
68     };
69     CPubseqGatewayCache cache("", "wrong si2sci", "/really_wrong_blob_prop");
70     cache.Open({});
71     EXPECT_EQ(2UL, cache.GetErrors().size());
72     EXPECT_EQ(expected_error_list, cache.GetErrors());
73     cache.ResetErrors();
74     EXPECT_TRUE(cache.GetErrors().empty());
75 }
76 
TEST(PubseqGatewayCacheRuntimeErrors,ErrorLimit)77 TEST(PubseqGatewayCacheRuntimeErrors, ErrorLimit) {
78     CPubseqGatewayCache cache("1", "2", "3");
79     for (size_t i = 0; i < CPubseqGatewayCache::kRuntimeErrorLimit; ++i) {
80         cache.Open({});
81     }
82     EXPECT_EQ(CPubseqGatewayCache::kRuntimeErrorLimit, cache.GetErrors().size());
83     cache.ResetErrors();
84     EXPECT_TRUE(cache.GetErrors().empty());
85 }
86 
87 END_SCOPE()
88