1 #ifndef FAKE_KEY_INCLUDED 2 #define FAKE_KEY_INCLUDED 3 4 /* 5 Copyright (c) 2014, 2021, Oracle and/or its affiliates. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License, version 2.0, 9 as published by the Free Software Foundation. 10 11 This program is also distributed with certain software (including 12 but not limited to OpenSSL) that is licensed under separate terms, 13 as designated in a particular file or component or in included license 14 documentation. The authors of MySQL hereby grant you an additional 15 permission to link the program and your derivative works with the 16 separately licensed software that they have included with MySQL. 17 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License, version 2.0, for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software Foundation, 25 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 26 27 // First include (the generated) my_config.h, to get correct platform defines. 28 #include "my_config.h" 29 #include <gtest/gtest.h> 30 31 #include "key.h" // KEY 32 33 34 /** 35 A fake class to make it easy to set up a KEY object. 36 37 Note that in this version the KEY object is only initialized with necessary 38 information to do operations on rec_per_key. 39 */ 40 41 class Fake_KEY : public KEY 42 { 43 public: 44 /** 45 Initialize the KEY object. 46 47 Only member variables needed for the rec_per_key interface are 48 currently initialized. 49 50 @param key_parts_arg number of key parts this index should have 51 @param unique unique or non-unique key 52 */ 53 Fake_KEY(unsigned int key_parts_arg,bool unique)54 Fake_KEY(unsigned int key_parts_arg, bool unique) 55 { 56 assert(key_parts_arg > 0); 57 58 flags= 0; 59 if (unique) 60 flags|= HA_NOSAME; 61 actual_flags= flags; 62 63 user_defined_key_parts= key_parts_arg; 64 actual_key_parts= key_parts_arg; 65 66 // Allocate memory for the two rec_per_key arrays 67 m_rec_per_key= new ulong[actual_key_parts]; 68 m_rec_per_key_float= new rec_per_key_t[actual_key_parts]; 69 set_rec_per_key_array(m_rec_per_key, m_rec_per_key_float); 70 71 // Initialize the rec_per_key arrays with default/unknown value 72 for (uint kp= 0; kp < actual_key_parts; kp++) 73 { 74 rec_per_key[kp]= 0; 75 set_records_per_key(kp, REC_PER_KEY_UNKNOWN); 76 } 77 } 78 ~Fake_KEY()79 ~Fake_KEY() 80 { 81 // free the memory for the two rec_per_key arrays 82 delete [] m_rec_per_key; 83 delete [] m_rec_per_key_float; 84 } 85 86 private: 87 // Storage for the two records per key arrays 88 ulong *m_rec_per_key; 89 rec_per_key_t *m_rec_per_key_float; 90 }; 91 92 #endif /* FAKE_KEY_INCLUDED */ 93