1 /* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #include <gtest/gtest.h>
24 
25 #include <my_global.h>
26 #include <my_sys.h>
27 
28 namespace mysys_my_load_path {
29 
TEST(Mysys,MyLoadPath)30 TEST(Mysys, MyLoadPath)
31 {
32   char dest[FN_REFLEN];
33 
34   static const std::string filename= "filename";
35 
36   // Path with absolute path component.
37   std::string absolute_path_name= FN_LIBCHAR + filename;
38   my_load_path(dest, absolute_path_name.c_str(), NULL);
39   EXPECT_STREQ(dest, absolute_path_name.c_str());
40 
41   // Path with home directory component.
42   dest[0]= '\0';
43   std::string home_dir_path_name= FN_HOMELIB + (FN_LIBCHAR + filename);
44   my_load_path(dest, home_dir_path_name.c_str(), NULL);
45   EXPECT_STREQ(dest, home_dir_path_name.c_str());
46 
47   // Path with current directory component.
48   dest[0]= '\0';
49   std::string parent_dir_path_name= FN_CURLIB + (FN_LIBCHAR + filename);
50   my_load_path(dest, parent_dir_path_name.c_str(), NULL);
51   char temp_buf[256];
52   my_getwd(temp_buf, sizeof(temp_buf), MYF(0));
53   EXPECT_STREQ(dest, (temp_buf+filename).c_str());
54 
55   // Path with prefix component appended.
56   dest[0]= '\0';
57   std::string prefix_path_name= "/basedir/";
58   my_load_path(dest, filename.c_str(), prefix_path_name.c_str());
59   EXPECT_STREQ(dest, (prefix_path_name+filename).c_str());
60 
61   // Path that has length FN_REFLEN-1
62   dest[0]= '\0';
63   std::string cur_dir_path_name;
64   for (int i= 0; i < (FN_REFLEN-3); i++)
65     cur_dir_path_name.append("y");
66   cur_dir_path_name= FN_CURLIB + (FN_LIBCHAR + cur_dir_path_name);
67   my_load_path(dest, cur_dir_path_name.c_str(), NULL);
68   EXPECT_STREQ(dest, cur_dir_path_name.c_str());
69 
70   // Path that has length FN_REFLEN.
71   dest[0]= '\0';
72   cur_dir_path_name.append("y");
73   my_load_path(dest, cur_dir_path_name.c_str(), NULL);
74   EXPECT_STREQ(dest, cur_dir_path_name.substr(0,FN_REFLEN-1).c_str());
75 
76   // Path that has length exceeding FN_REFLEN
77   dest[0]= '\0';
78   cur_dir_path_name.append("y");
79   my_load_path(dest, cur_dir_path_name.c_str(), NULL);
80   EXPECT_STREQ(dest, cur_dir_path_name.substr(0,FN_REFLEN-1).c_str());
81 }
82 }
83