├── .gitignore
├── .idea
└── vcs.xml
├── CMakeLists.txt
├── README.md
├── arrays
├── CMakeLists.txt
├── jvector.cc
├── jvector.h
├── jvector_test.cc
├── jvector_test.h
└── main.cc
├── binary_search_tree
├── CMakeLists.txt
├── bst_simple.cc
├── bst_simple.h
└── main.cc
├── graphs
├── CMakeLists.txt
├── DirectedGraph.cc
├── DirectedGraph.h
├── Graph.cc
├── Graph.h
├── GraphRepresentation.cc
├── GraphRepresentation.h
├── experiments.h
└── main.cc
├── hash_table
├── CMakeLists.txt
├── hash_object.h
├── hash_table.cc
├── hash_table.h
├── hash_tables_tests.cc
├── hash_tables_tests.h
└── main.cc
├── lib
└── googletest
│ ├── CHANGES
│ ├── CMakeLists.txt
│ ├── CONTRIBUTORS
│ ├── LICENSE
│ ├── Makefile.am
│ ├── README.md
│ ├── build-aux
│ └── .keep
│ ├── cmake
│ └── internal_utils.cmake
│ ├── codegear
│ ├── gtest.cbproj
│ ├── gtest.groupproj
│ ├── gtest_all.cc
│ ├── gtest_link.cc
│ ├── gtest_main.cbproj
│ └── gtest_unittest.cbproj
│ ├── configure.ac
│ ├── docs
│ ├── AdvancedGuide.md
│ ├── DevGuide.md
│ ├── Documentation.md
│ ├── FAQ.md
│ ├── Primer.md
│ ├── PumpManual.md
│ ├── Samples.md
│ ├── V1_5_AdvancedGuide.md
│ ├── V1_5_Documentation.md
│ ├── V1_5_FAQ.md
│ ├── V1_5_Primer.md
│ ├── V1_5_PumpManual.md
│ ├── V1_5_XcodeGuide.md
│ ├── V1_6_AdvancedGuide.md
│ ├── V1_6_Documentation.md
│ ├── V1_6_FAQ.md
│ ├── V1_6_Primer.md
│ ├── V1_6_PumpManual.md
│ ├── V1_6_Samples.md
│ ├── V1_6_XcodeGuide.md
│ ├── V1_7_AdvancedGuide.md
│ ├── V1_7_Documentation.md
│ ├── V1_7_FAQ.md
│ ├── V1_7_Primer.md
│ ├── V1_7_PumpManual.md
│ ├── V1_7_Samples.md
│ ├── V1_7_XcodeGuide.md
│ └── XcodeGuide.md
│ ├── include
│ └── gtest
│ │ ├── gtest-death-test.h
│ │ ├── gtest-message.h
│ │ ├── gtest-param-test.h
│ │ ├── gtest-param-test.h.pump
│ │ ├── gtest-printers.h
│ │ ├── gtest-spi.h
│ │ ├── gtest-test-part.h
│ │ ├── gtest-typed-test.h
│ │ ├── gtest.h
│ │ ├── gtest_pred_impl.h
│ │ ├── gtest_prod.h
│ │ └── internal
│ │ ├── custom
│ │ ├── gtest-port.h
│ │ ├── gtest-printers.h
│ │ └── gtest.h
│ │ ├── gtest-death-test-internal.h
│ │ ├── gtest-filepath.h
│ │ ├── gtest-internal.h
│ │ ├── gtest-linked_ptr.h
│ │ ├── gtest-param-util-generated.h
│ │ ├── gtest-param-util-generated.h.pump
│ │ ├── gtest-param-util.h
│ │ ├── gtest-port-arch.h
│ │ ├── gtest-port.h
│ │ ├── gtest-string.h
│ │ ├── gtest-tuple.h
│ │ ├── gtest-tuple.h.pump
│ │ ├── gtest-type-util.h
│ │ └── gtest-type-util.h.pump
│ ├── m4
│ ├── acx_pthread.m4
│ └── gtest.m4
│ ├── make
│ └── Makefile
│ ├── msvc
│ ├── gtest-md.sln
│ ├── gtest-md.vcproj
│ ├── gtest.sln
│ ├── gtest.vcproj
│ ├── gtest_main-md.vcproj
│ ├── gtest_main.vcproj
│ ├── gtest_prod_test-md.vcproj
│ ├── gtest_prod_test.vcproj
│ ├── gtest_unittest-md.vcproj
│ └── gtest_unittest.vcproj
│ ├── samples
│ ├── prime_tables.h
│ ├── sample1.cc
│ ├── sample1.h
│ ├── sample10_unittest.cc
│ ├── sample1_unittest.cc
│ ├── sample2.cc
│ ├── sample2.h
│ ├── sample2_unittest.cc
│ ├── sample3-inl.h
│ ├── sample3_unittest.cc
│ ├── sample4.cc
│ ├── sample4.h
│ ├── sample4_unittest.cc
│ ├── sample5_unittest.cc
│ ├── sample6_unittest.cc
│ ├── sample7_unittest.cc
│ ├── sample8_unittest.cc
│ └── sample9_unittest.cc
│ ├── scripts
│ ├── common.py
│ ├── fuse_gtest_files.py
│ ├── gen_gtest_pred_impl.py
│ ├── gtest-config.in
│ ├── pump.py
│ ├── release_docs.py
│ ├── test
│ │ └── Makefile
│ ├── upload.py
│ └── upload_gtest.py
│ ├── src
│ ├── gtest-all.cc
│ ├── gtest-death-test.cc
│ ├── gtest-filepath.cc
│ ├── gtest-internal-inl.h
│ ├── gtest-port.cc
│ ├── gtest-printers.cc
│ ├── gtest-test-part.cc
│ ├── gtest-typed-test.cc
│ ├── gtest.cc
│ └── gtest_main.cc
│ ├── test
│ ├── gtest-death-test_ex_test.cc
│ ├── gtest-death-test_test.cc
│ ├── gtest-filepath_test.cc
│ ├── gtest-linked_ptr_test.cc
│ ├── gtest-listener_test.cc
│ ├── gtest-message_test.cc
│ ├── gtest-options_test.cc
│ ├── gtest-param-test2_test.cc
│ ├── gtest-param-test_test.cc
│ ├── gtest-param-test_test.h
│ ├── gtest-port_test.cc
│ ├── gtest-printers_test.cc
│ ├── gtest-test-part_test.cc
│ ├── gtest-tuple_test.cc
│ ├── gtest-typed-test2_test.cc
│ ├── gtest-typed-test_test.cc
│ ├── gtest-typed-test_test.h
│ ├── gtest-unittest-api_test.cc
│ ├── gtest_all_test.cc
│ ├── gtest_break_on_failure_unittest.py
│ ├── gtest_break_on_failure_unittest_.cc
│ ├── gtest_catch_exceptions_test.py
│ ├── gtest_catch_exceptions_test_.cc
│ ├── gtest_color_test.py
│ ├── gtest_color_test_.cc
│ ├── gtest_env_var_test.py
│ ├── gtest_env_var_test_.cc
│ ├── gtest_environment_test.cc
│ ├── gtest_filter_unittest.py
│ ├── gtest_filter_unittest_.cc
│ ├── gtest_help_test.py
│ ├── gtest_help_test_.cc
│ ├── gtest_list_tests_unittest.py
│ ├── gtest_list_tests_unittest_.cc
│ ├── gtest_main_unittest.cc
│ ├── gtest_no_test_unittest.cc
│ ├── gtest_output_test.py
│ ├── gtest_output_test_.cc
│ ├── gtest_output_test_golden_lin.txt
│ ├── gtest_pred_impl_unittest.cc
│ ├── gtest_premature_exit_test.cc
│ ├── gtest_prod_test.cc
│ ├── gtest_repeat_test.cc
│ ├── gtest_shuffle_test.py
│ ├── gtest_shuffle_test_.cc
│ ├── gtest_sole_header_test.cc
│ ├── gtest_stress_test.cc
│ ├── gtest_test_utils.py
│ ├── gtest_throw_on_failure_ex_test.cc
│ ├── gtest_throw_on_failure_test.py
│ ├── gtest_throw_on_failure_test_.cc
│ ├── gtest_uninitialized_test.py
│ ├── gtest_uninitialized_test_.cc
│ ├── gtest_unittest.cc
│ ├── gtest_xml_outfile1_test_.cc
│ ├── gtest_xml_outfile2_test_.cc
│ ├── gtest_xml_outfiles_test.py
│ ├── gtest_xml_output_unittest.py
│ ├── gtest_xml_output_unittest_.cc
│ ├── gtest_xml_test_utils.py
│ ├── production.cc
│ └── production.h
│ └── xcode
│ ├── Config
│ ├── DebugProject.xcconfig
│ ├── FrameworkTarget.xcconfig
│ ├── General.xcconfig
│ ├── ReleaseProject.xcconfig
│ ├── StaticLibraryTarget.xcconfig
│ └── TestTarget.xcconfig
│ ├── Resources
│ └── Info.plist
│ ├── Samples
│ └── FrameworkSample
│ │ ├── Info.plist
│ │ ├── WidgetFramework.xcodeproj
│ │ └── project.pbxproj
│ │ ├── runtests.sh
│ │ ├── widget.cc
│ │ ├── widget.h
│ │ └── widget_test.cc
│ ├── Scripts
│ ├── runtests.sh
│ └── versiongenerate.py
│ └── gtest.xcodeproj
│ └── project.pbxproj
├── linked_lists
├── CMakeLists.txt
├── main.cc
├── src
│ ├── CMakeLists.txt
│ ├── linked_list.cc
│ ├── linked_list.h
│ └── list_element.h
└── tests
│ ├── CMakeLists.txt
│ ├── lib
│ └── list_tests.cc
├── merge_sort
├── CMakeLists.txt
├── main.cc
├── merge_sort.cc
├── merge_sort.h
├── random.txt
├── test_merge_sort.cc
└── test_merge_sort.h
├── priority_queue
├── CMakeLists.txt
├── main.cc
├── priority_queue.cc
└── priority_queue.h
├── queue_array
├── CMakeLists.txt
├── main.cc
├── src
│ ├── CMakeLists.txt
│ ├── queue_array.cc
│ └── queue_array.h
└── tests
│ ├── CMakeLists.txt
│ └── queue_array_tests.cc
├── queue_linked_list
├── CMakeLists.txt
├── main.cc
├── src
│ ├── CMakeLists.txt
│ ├── list_element.h
│ ├── queue_linked_list.cc
│ └── queue_linked_list.h
└── tests
│ ├── CMakeLists.txt
│ └── queue_llist_tests.cc
├── quick_sort
├── CMakeLists.txt
├── main.cc
├── quick_sort.cc
├── quick_sort.h
├── test_sort.cc
└── test_sort.h
└── valgrind.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 |
3 | add_subdirectory(arrays)
4 | add_subdirectory(linked_lists)
5 | add_subdirectory(queue_array)
6 | add_subdirectory(queue_linked_list)
7 | add_subdirectory(hash_table)
8 | add_subdirectory(binary_search_tree)
9 | add_subdirectory(priority_queue)
10 | add_subdirectory(merge_sort)
11 | add_subdirectory(quick_sort)
12 | add_subdirectory(graphs)
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Practice C++
2 |
3 | Part of my daily plan for studying C++.
4 |
5 | **Important**
6 |
7 | This code may be terrible and buggy. It's been a few months since I've looked at it.
--------------------------------------------------------------------------------
/arrays/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(arrays_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES main.cc)
10 | add_executable(arrays ${SOURCE_FILES})
11 |
--------------------------------------------------------------------------------
/arrays/jvector.h:
--------------------------------------------------------------------------------
1 | #ifndef PRACTICE_CPP_JARRAY_H
2 | #define PRACTICE_CPP_JARRAY_H
3 |
4 | namespace jw {
5 |
6 | static const int kMinCapacity = 16;
7 | static const int kGrowthFactor = 2;
8 | static const int kShrinkFactor = 4;
9 |
10 | class JVector {
11 | public:
12 | JVector(int capacity);
13 | JVector(const JVector &other) = default;
14 | // JVector &operator=(const JVector &other) = default;
15 | ~JVector();
16 | // Returns the number of items stored in the vector.
17 | int GetSize() const;
18 | bool IsEmpty() const;
19 | // Returns the capacity of the vector.
20 | int GetCapacity() const;
21 | // Prints out public information about the vector.
22 | void DebugString() const;
23 | // Appends the given value to the end of the vector.
24 | void Push(int value);
25 | // Returns the value stored at the given index
26 | int GetValueAt(int index) const;
27 | // Returns the last item in the vector, and removes it.
28 | int Pop();
29 | // Inserts the given value at the given index, shifting
30 | // current and trailing items to the right.
31 | void Insert(int index, int value);
32 | // Prepends the given value to the vector, shifting trailing
33 | // items to the right.
34 | void Prepend(int value);
35 | // Deletes item at index, shifting all trailing elements left.
36 | void Delete(int index);
37 | // Removes all instances of value from the vector.
38 | void Remove(int value);
39 | // Looks for value and returns first index with that value, -1 if not found.
40 | int Find(int value) const;
41 |
42 | private:
43 | // The actual capacity that can be accommodated before a resize is required
44 | int capacity_{kMinCapacity};
45 | // The number of items currently stored
46 | int size_{0};
47 | // The storage array where ints are stored
48 | std::unique_ptr data_;
49 | // Determines the array size (in terms of power of growth factor)
50 | // required to accommodate the given capacity
51 | int DetermineCapacity(int capacity) const;
52 | // Checks to see if resizing is required for the given capacity
53 | // and grows or shrinks the vector as needed.
54 | void ResizeForSize(int candidate_size);
55 | // Increases the capacity of the vector.
56 | void IncreaseSize();
57 | // Decreases the capacity of the vector.
58 | void DecreaseSize();
59 | };
60 |
61 | } // namespace jw
62 |
63 | #endif // PRACTICE_CPP_JARRAY_H
64 |
--------------------------------------------------------------------------------
/arrays/jvector_test.h:
--------------------------------------------------------------------------------
1 | #ifndef PROJECT_JVECTOR_TEST_H
2 | #define PROJECT_JVECTOR_TEST_H
3 |
4 | namespace jw {
5 |
6 | class JVectorTest {
7 | public:
8 | void RunTests() const;
9 | void TestSize() const;
10 | // Tests increases and decreases in capacity based on number of items stored.
11 | void TestCapacity() const;
12 | void TestIsEmpty() const;
13 | void TestGetValueAt() const;
14 | void TestPop() const;
15 | void TestInsert() const;
16 | void TestPrepend() const;
17 | void TestDelete() const;
18 | void TestRemove() const;
19 | void TestFind() const;
20 | };
21 |
22 | } // namespace jw
23 |
24 | #endif // PROJECT_JVECTOR_TEST_H
25 |
--------------------------------------------------------------------------------
/arrays/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "jvector.h"
5 | #include "jvector.cc"
6 | #include "jvector_test.h"
7 | #include "jvector_test.cc"
8 |
9 | void StandardExperiment();
10 |
11 | int main(int argc, char *argv[]) {
12 |
13 | jw::JVectorTest tester;
14 | tester.RunTests();
15 |
16 | // int initial_capacity = 1;
17 | //
18 | // std::cout << "Enter how many items you want to store: " << std::endl;
19 | // std::cin >> initial_capacity;
20 | //
21 | // jw::JVector test_v(initial_capacity);
22 | //
23 | // assert(test_v.IsEmpty());
24 | //
25 | // for (int i = 0; i < 77; ++i) {
26 | // test_v.Push(i + 1);
27 | // }
28 |
29 | // test_v.DebugString();
30 |
31 | // StandardExperiment();
32 |
33 | return EXIT_SUCCESS;
34 | }
35 |
36 | void StandardExperiment() {
37 |
38 | std::cout << "Now messing with std implementation." << std::endl;
39 |
40 | std::vector myv{12, 23, 5, 3};
41 |
42 | std::cout << "Size: " << myv.size() << std::endl;
43 | std::cout << "Capacity: " << myv.capacity() << std::endl;
44 |
45 | std::cout << "Adding a few items" << std::endl;
46 |
47 | myv.push_back(4);
48 | myv.push_back(12);
49 | myv.push_back(45);
50 |
51 | std::cout << "Size: " << myv.size() << std::endl;
52 | std::cout << "Capacity: " << myv.capacity() << std::endl;
53 | std::cout << "Popping 1" << std::endl;
54 |
55 | myv.pop_back();
56 |
57 | std::cout << "Size: " << myv.size() << std::endl;
58 | std::cout << "Capacity: " << myv.capacity() << std::endl;
59 |
60 | std::cout << "Items:" << std::endl;
61 | for (int value : myv) {
62 | std::cout << value << std::endl;
63 | }
64 |
65 | std::cout << "Inserting at index 4" << std::endl;
66 | myv.insert(myv.begin() + 4, 99);
67 |
68 | std::cout << "Items:" << std::endl;
69 | for (int value : myv) {
70 | std::cout << value << std::endl;
71 | }
72 |
73 | //myv.reserve(120);
74 |
75 | for (int i = 0; i < 75; i++) {
76 | myv.push_back(i + 3);
77 | }
78 |
79 | std::cout << "Size: " << myv.size() << std::endl;
80 | std::cout << "Capacity: " << myv.capacity() << std::endl;
81 |
82 | std::cout << "Collapsing" << std::endl;
83 | myv.shrink_to_fit();
84 | std::cout << "Capacity: " << myv.capacity() << std::endl;
85 |
86 | std::cout << "Items:" << std::endl;
87 | for (unsigned long j = 0; j < myv.size(); ++j) {
88 | std::cout << j << ": " << myv.at(j) << std::endl;
89 | }
90 |
91 | std::cout << "Erasing items from indices from 4 to 11" << std::endl;
92 | myv.erase(myv.begin() + 4, myv.begin() + 12);
93 |
94 | std::cout << "Items:" << std::endl;
95 | for (unsigned long k = 0; k < myv.size(); ++k) {
96 | std::cout << k << ": " << myv.at(k) << std::endl;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/binary_search_tree/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(binary_search_tree_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES main.cc)
10 |
11 | add_executable(binary_search_tree ${SOURCE_FILES} ${HEADER_FILES})
12 |
--------------------------------------------------------------------------------
/binary_search_tree/bst_simple.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #ifndef PROJECT_BINARY_SEARCH_TREE_H
4 | #define PROJECT_BINARY_SEARCH_TREE_H
5 |
6 | namespace jw {
7 |
8 | struct BSTNode {
9 | int data;
10 | BSTNode* left;
11 | BSTNode* right;
12 | };
13 |
14 | // Returns a new node for our BST
15 | BSTNode* GetNewNode(int value);
16 | // Returns true if given value is in our tree
17 | bool Search(BSTNode* node, int value);
18 | // Frees memory allocated for the tree.
19 | void DeleteTree(BSTNode* node);
20 | // Returns the minimum value stored in the tree,
21 | // or -1 if tree is empty
22 | int GetMin(BSTNode* node);
23 | // Returns the maximum value stored in the tree,
24 | // or -1 if tree is empty
25 | int GetMax(BSTNode* node);
26 | // Returns height of the tree, 0 if empty
27 | int GetHeight(BSTNode* node);
28 | // Print out the items in the tree in level order
29 | void PrintBFS(BSTNode* node);
30 | // Print out the items in the tree in order (inorder)
31 | void PrintInOrder(BSTNode* node);
32 | // Returns true if tree is a binary search tree
33 | bool IsBinarySearchTree(BSTNode* node);
34 | // Returns true if all items in the given tree are between the given values
35 | bool IsBetween(BSTNode* node, int min, int max);
36 | // Delete a specific node from the tree
37 | BSTNode* DeleteValue(BSTNode* node, int value);
38 | // Returns the node in the tree with the minimum value
39 | BSTNode* GetMinNode(BSTNode* node);
40 | // Returns the in-order successor of the given value
41 | BSTNode* GetSuccessor(BSTNode* node, int value);
42 |
43 | } // namespace jw
44 |
45 | #endif // PROJECT_BINARY_SEARCH_TREE_H
46 |
--------------------------------------------------------------------------------
/binary_search_tree/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "bst_simple.cc"
5 | #include "bst_simple.h"
6 |
7 | int main(int argc, char* argv[]) {
8 | using namespace jw;
9 |
10 | BSTNode* root = nullptr;
11 |
12 | root = Insert(root, 15);
13 | root = Insert(root, 10);
14 | root = Insert(root, 12);
15 | root = Insert(root, 8);
16 | root = Insert(root, 9);
17 | root = Insert(root, 5);
18 | root = Insert(root, 7);
19 | root = Insert(root, 23);
20 | root = Insert(root, 16);
21 | root = Insert(root, 44);
22 | root = Insert(root, 2);
23 | root = Insert(root, 32);
24 |
25 | int min = GetMin(root);
26 | int max = GetMax(root);
27 | int height = GetHeight(root);
28 |
29 | std::cout << "Min: " << min << std::endl;
30 | assert(min == 2);
31 | std::cout << "Max: " << max << std::endl;
32 | assert(max == 44);
33 | std::cout << "Height: " << height << std::endl;
34 | assert(height == 5);
35 |
36 | std::cout << "Tree items (breadth-first): ";
37 | PrintBFS(root);
38 | std::cout << std::endl;
39 |
40 | std::cout << "Tree items (in order): ";
41 | PrintInOrder(root);
42 | std::cout << std::endl;
43 |
44 | std::cout << "Is a binary search tree: " << IsBinarySearchTree(root)
45 | << std::endl;
46 | assert(IsBinarySearchTree(root));
47 |
48 | BSTNode* suc1 = GetSuccessor(root, 5);
49 | std::cout << "Successor to 5 (2 children), should be 7: " << suc1->data
50 | << std::endl;
51 | assert(suc1->data == 7);
52 |
53 | BSTNode* suc1a = GetSuccessor(root, 7);
54 | std::cout << "Successor to 7 (0 children), should be 8: " << suc1a->data
55 | << std::endl;
56 | assert(suc1a->data == 8);
57 |
58 | BSTNode* suc2 = GetSuccessor(root, 12);
59 | std::cout << "Successor to 12 (0 children), should be 15: " << suc2->data
60 | << std::endl;
61 | assert(suc2->data == 15);
62 |
63 | BSTNode* suc3 = GetSuccessor(root, 15);
64 | std::cout << "Successor to 15 (2 children), should be 16: " << suc3->data
65 | << std::endl;
66 | assert(suc3->data == 16);
67 |
68 | // bad tree
69 | BSTNode* otherroot = GetNewNode(25);
70 | BSTNode* node1 = GetNewNode(12);
71 | BSTNode* node2 = GetNewNode(15);
72 | BSTNode* node3 = GetNewNode(85);
73 | otherroot->left = node1;
74 | otherroot->right = node2;
75 | otherroot->left->right = node3;
76 |
77 | std::cout << "Is a binary search tree: " << IsBinarySearchTree(otherroot)
78 | << std::endl;
79 | assert(!IsBinarySearchTree(otherroot));
80 |
81 | std::cout << "Removing 2 (no children)" << std::endl;
82 | root = DeleteValue(root, 2);
83 | std::cout << "Tree items (in order): ";
84 | PrintInOrder(root);
85 | std::cout << std::endl;
86 |
87 | std::cout << "Removing 5 (one child)" << std::endl;
88 | root = DeleteValue(root, 5);
89 | std::cout << "Tree items (in order): ";
90 | PrintInOrder(root);
91 | std::cout << std::endl;
92 |
93 | std::cout << "Removing 10 (2 children)" << std::endl;
94 | root = DeleteValue(root, 10);
95 | std::cout << "Tree items (in order): ";
96 | PrintInOrder(root);
97 | std::cout << std::endl;
98 |
99 | DeleteTree(root);
100 | DeleteTree(otherroot);
101 |
102 | return EXIT_SUCCESS;
103 | }
104 |
--------------------------------------------------------------------------------
/graphs/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(graphse_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES
10 | main.cc
11 | Graph.cc
12 | GraphRepresentation.cc
13 | DirectedGraph.cc
14 | )
15 |
16 | add_executable(graphs ${SOURCE_FILES} ${HEADER_FILES})
17 |
--------------------------------------------------------------------------------
/graphs/DirectedGraph.cc:
--------------------------------------------------------------------------------
1 | #include "DirectedGraph.h"
2 |
3 | namespace jw {
4 |
5 | DirectedGraph::DirectedGraph(const std::string representation_type) {
6 | representation_ = GraphRepresentation::GetRepresentation(
7 | representation_type, GraphRepresentation::kGraphTypeDirected);
8 | }
9 |
10 | void DirectedGraph::AddEdge(const int source, const int destination) {
11 | representation_->AddEdge(source, destination);
12 | }
13 |
14 | void DirectedGraph::DFS() { representation_->DFS(); }
15 |
16 | void DirectedGraph::BFS() { representation_->BFS(); }
17 |
18 | bool DirectedGraph::ContainsCycle() { return representation_->ContainsCycle(); }
19 |
20 | void DirectedGraph::PrintDebug() { representation_->PrintDebug(); }
21 |
22 | const int DirectedGraph::GetVertexCount() {
23 | return representation_->vertices_;
24 | }
25 |
26 | } // namespace jw
--------------------------------------------------------------------------------
/graphs/DirectedGraph.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Graph.h"
3 |
4 | #ifndef PROJECT_DIRECTEDGRAPH_H
5 | #define PROJECT_DIRECTEDGRAPH_H
6 |
7 | namespace jw {
8 |
9 | class DirectedGraph : public Graph {
10 | public:
11 | DirectedGraph(const std::string);
12 | ~DirectedGraph() = default;
13 | DirectedGraph(const DirectedGraph &) = delete;
14 | DirectedGraph &operator=(const DirectedGraph &) = delete;
15 |
16 | void AddEdge(const int source, const int destination);
17 | void DFS();
18 | void BFS();
19 | bool ContainsCycle();
20 | void PrintDebug();
21 | const int GetVertexCount();
22 | };
23 |
24 | } // namespace jw
25 |
26 | #endif // PROJECT_DIRECTEDGRAPH_H
27 |
--------------------------------------------------------------------------------
/graphs/Graph.cc:
--------------------------------------------------------------------------------
1 | #include "Graph.h"
2 |
3 | namespace jw {
4 |
5 |
6 | } // namespace jw
--------------------------------------------------------------------------------
/graphs/Graph.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "GraphRepresentation.h"
4 |
5 | #ifndef PROJECT_GRAPH_H
6 | #define PROJECT_GRAPH_H
7 |
8 | namespace jw {
9 |
10 | class Graph {
11 | public:
12 | Graph() {};
13 | Graph(const std::string) {}
14 | ~Graph() = default;
15 | Graph(const Graph &) = delete;
16 | Graph &operator=(const Graph &) = delete;
17 |
18 | virtual void AddEdge(const int source, const int destination) = 0;
19 | virtual void DFS() = 0;
20 | virtual void BFS() = 0;
21 | virtual void PrintDebug() = 0;
22 |
23 | std::unique_ptr representation_;
24 | int vertices_;
25 | };
26 |
27 | } // namespace jw
28 |
29 | #endif // PROJECT_GRAPH_H
30 |
--------------------------------------------------------------------------------
/graphs/GraphRepresentation.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #ifndef PROJECT_GRAPH_REPRESENTATION_H
10 | #define PROJECT_GRAPH_REPRESENTATION_H
11 |
12 | namespace jw {
13 |
14 | class GraphRepresentation {
15 | public:
16 | static const std::string kRepresentationTypeList;
17 | static const std::string kRepresentationTypeMatrix;
18 | static const std::string kGraphTypeDirected;
19 | static const std::string kGraphTypeUndirected;
20 |
21 | static std::unique_ptr GetRepresentation(
22 | const std::string representation_type, const std::string graph_type);
23 |
24 | GraphRepresentation() {}
25 | GraphRepresentation(const std::string graph_type);
26 | ~GraphRepresentation() = default;
27 | GraphRepresentation(const GraphRepresentation &) = delete;
28 | GraphRepresentation &operator=(const GraphRepresentation &) = delete;
29 |
30 | virtual void AddEdge(const int source, const int destination) = 0;
31 | virtual void DFS() = 0;
32 | virtual void BFS() = 0;
33 | virtual bool ContainsCycle() = 0;
34 | virtual void PrintDebug() = 0;
35 |
36 | std::string type_;
37 | int vertices_;
38 | };
39 |
40 | class GraphRepresentationList : public GraphRepresentation {
41 | public:
42 | GraphRepresentationList(const std::string graph_type)
43 | : GraphRepresentation(graph_type) {}
44 | void AddEdge(const int source, const int destination);
45 | void DFS();
46 | void BFS();
47 | bool ContainsCycle();
48 | void PrintDebug();
49 |
50 | std::vector> adj_list_;
51 | };
52 |
53 | // class GraphRepresentationMatrix : public GraphRepresentation {
54 | // public:
55 | // GraphRepresentationMatrix(const std::string graph_type)
56 | // : GraphRepresentation(graph_type) {}
57 | // void AddEdge(const int source, const int destination);
58 | // void DFS();
59 | // void BFS();
60 | // bool ContainsCycle();
61 | // void PrintDebug();
62 | //};
63 |
64 | } // namespace jw
65 |
66 | #endif // PROJECT_GRAPH_REPRESENTATION_H
67 |
--------------------------------------------------------------------------------
/graphs/experiments.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #ifndef PROJECT_EXPERIMENTS_H
7 | #define PROJECT_EXPERIMENTS_H
8 |
9 | using namespace std;
10 |
11 | void print_vector() {
12 | const unsigned long f = 30;
13 |
14 | std::vector mynums(f);
15 |
16 | std::cout << mynums.at(3) << std::endl;
17 | }
18 |
19 | void print_random() {
20 | cout << "Junk random: ";
21 | srand(time(0));
22 | cout << rand() % 100 << endl;
23 |
24 | cout << "Real random: ";
25 | std::random_device rng;
26 | std::uniform_int_distribution dist(0, 99);
27 | int randnum = dist(rng);
28 | cout << randnum << endl;
29 | }
30 |
31 | void string_fun() {
32 | string foo("Hello");
33 | string other("Hello there");
34 |
35 | cout << foo.size() << endl;
36 | cout << foo.empty() << endl;
37 |
38 | cout << foo.append(" there") << endl;
39 | cout << foo << endl;
40 |
41 | if (foo == other) {
42 | cout << "They match with =" << endl;
43 | }
44 |
45 | if (foo.compare(other) == 0) {
46 | cout << "They match with compare" << endl;
47 | }
48 |
49 | cout << "Copying a substring..." << endl;
50 | string copy;
51 | copy.assign(foo, 0, 5);
52 |
53 | cout << "New: " << copy << endl;
54 | copy.append(" friend");
55 | cout << copy << endl;
56 | cout << foo << endl;
57 |
58 | cout << "Position of there: " << foo.find("there", 0) << endl;
59 |
60 | cout << "Removing 'there'" << endl;
61 | foo.erase(foo.find("there", 0), 5);
62 | cout << foo << endl;
63 | }
64 |
65 | void input_test() {
66 | std::string my_input;
67 |
68 | std::cout << "Enter a number: ";
69 | getline(std::cin, my_input);
70 |
71 | int num = std::stoi(my_input);
72 | std::cout << "You said " << num << std::endl;
73 | }
74 |
75 | void vectors() {
76 | std::vector nums(100);
77 | std::vector strings(5);
78 |
79 | cout << "Default int: " << nums.at(2) << endl;
80 | cout << "Default string: " << strings.at(2) << endl;
81 |
82 | strings[2] = "howdy";
83 | cout << "New string: " << strings.at(2) << endl;
84 |
85 | cout << "Size of strings vector: " << strings.size() << endl;
86 |
87 | cout << "Contents of string vector:" << endl;
88 | for (int i = 0; i < strings.size(); ++i) {
89 | cout << i << ": " << strings.at(i) << endl;
90 | }
91 | }
92 |
93 | #endif // PROJECT_EXPERIMENTS_H
94 |
--------------------------------------------------------------------------------
/graphs/main.cc:
--------------------------------------------------------------------------------
1 | #include "DirectedGraph.h"
2 | #include "Graph.h"
3 | //#include "experiments.h"
4 |
5 | int main(int argc, char* argv[]) {
6 | using namespace jw;
7 |
8 | // print_vector();
9 | // print_random();
10 | // string_fun();
11 | // input_test();
12 | // vectors();
13 |
14 | auto dg = new DirectedGraph(GraphRepresentation::kRepresentationTypeList);
15 |
16 | dg->AddEdge(0, 1);
17 | dg->AddEdge(0, 5);
18 | dg->AddEdge(1, 2);
19 | dg->AddEdge(2, 4);
20 | dg->AddEdge(2, 6);
21 | dg->AddEdge(3, 2);
22 | dg->AddEdge(5, 8);
23 | dg->AddEdge(6, 5);
24 | dg->AddEdge(7, 5);
25 | // dg->AddEdge(8, 6); // uncomment to create cycle
26 |
27 | dg->DFS();
28 | dg->BFS();
29 | dg->PrintDebug();
30 |
31 | printf("Contains cycle: %d\n", dg->ContainsCycle());
32 |
33 | const int vertices = dg->GetVertexCount();
34 |
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/hash_table/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(hash_table_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES main.cc)
10 |
11 | add_executable(hash_table ${SOURCE_FILES} ${HEADER_FILES})
12 |
--------------------------------------------------------------------------------
/hash_table/hash_object.h:
--------------------------------------------------------------------------------
1 | #ifndef PROJECT_HASH_OBJECT_H
2 | #define PROJECT_HASH_OBJECT_H
3 |
4 | namespace jw {
5 |
6 | class HashObject {
7 | public:
8 | HashObject() {}
9 | ~HashObject() {}
10 | HashObject(const HashObject &) = delete;
11 | HashObject &operator=(const HashObject &) = default;
12 |
13 | std::string &GetKey() { return key_; }
14 | std::string &GetValue() { return value_; }
15 | void SetAsDummy() {
16 | key_ = GetDummyKey();
17 | value_ = "";
18 | }
19 | void SetKey(const std::string key) { key_ = key; }
20 | void SetValue(const std::string value) { value_ = value; }
21 | static const std::string GetDummyKey() { return ""; }
22 | static const std::string GetNullKey() { return ""; }
23 |
24 | private:
25 | std::string key_;
26 | std::string value_;
27 | };
28 |
29 | } // namespace jw
30 |
31 | #endif // PROJECT_HASH_OBJECT_H
32 |
--------------------------------------------------------------------------------
/hash_table/hash_table.cc:
--------------------------------------------------------------------------------
1 | #include "hash_table.h"
2 |
3 | namespace jw {
4 |
5 | HashTable::HashTable(const int size) {
6 | size_ = size;
7 | data_ = new HashObject[size];
8 | assert(data_ != nullptr);
9 |
10 | for (int i = 0; i < size; ++i) {
11 | data_[i].SetKey(HashObject::GetNullKey());
12 | }
13 | }
14 |
15 | HashTable::~HashTable() { delete[] data_; }
16 |
17 | int HashTable::Hash(const std::string key) {
18 | int hash = 0;
19 |
20 | int key_length = static_cast(key.length());
21 | for (int i = 0; i < key_length; ++i) {
22 | hash = hash * 31 + key[i];
23 | }
24 |
25 | return abs(hash % size_);
26 | }
27 |
28 | bool HashTable::Exists(const std::string key) {
29 | int index = Hash(key);
30 | int original_index = index;
31 | bool found = false;
32 |
33 | while (data_[index].GetKey() != HashObject::GetNullKey()) {
34 | if (data_[index].GetKey() == key) {
35 | found = true;
36 | break;
37 | }
38 | index = (index + 1) % size_;
39 | if (index == original_index) {
40 | break;
41 | }
42 | }
43 |
44 | return found;
45 | }
46 |
47 | void HashTable::Add(HashObject* object) {
48 | int index = Hash(object->GetKey());
49 | int original_index = index;
50 | int dummyIndex = -1;
51 |
52 | bool found = false;
53 | while (data_[index].GetKey() != HashObject::GetNullKey()) {
54 | if (data_[index].GetKey() == object->GetKey()) {
55 | found = true;
56 | break;
57 | } else if (data_[index].GetKey() == HashObject::GetDummyKey()) {
58 | dummyIndex = index;
59 | }
60 | index = (index + 1) % size_;
61 | if (index == original_index) {
62 | return;
63 | }
64 | }
65 |
66 | if (!found && dummyIndex != -1) {
67 | index = dummyIndex;
68 | }
69 |
70 | data_[index].SetKey(object->GetKey());
71 | data_[index].SetValue(object->GetValue());
72 | }
73 |
74 | void HashTable::PrintDebug() {
75 | for (int i = 0; i < size_; ++i) {
76 | std::cout << i << ": " << data_[i].GetKey() << ":" << data_[i].GetValue()
77 | << std::endl;
78 | }
79 |
80 | std::cout << "--------------------------\n" << std::endl;
81 | }
82 |
83 | void HashTable::Remove(const std::string key) {
84 | int index = Hash(key);
85 | int original_index = index;
86 |
87 | while (data_[index].GetKey() != HashObject::GetNullKey()) {
88 | if (data_[index].GetKey() == key) {
89 | data_[index].SetKey(HashObject::GetDummyKey());
90 | data_[index].SetValue("");
91 | break;
92 | }
93 | index = (index + 1) % size_;
94 | if (index == original_index) {
95 | break;
96 | }
97 | }
98 | }
99 |
100 | const std::string HashTable::Get(const std::string key) {
101 | int index = Hash(key);
102 | int original_index = index;
103 |
104 | while (data_[index].GetKey() != HashObject::GetNullKey()) {
105 | if (data_[index].GetKey() == key) {
106 | return data_[index].GetValue();
107 | }
108 | index = (index + 1) % size_;
109 | if (index == original_index) {
110 | break;
111 | }
112 | }
113 |
114 | return NULL;
115 | }
116 | };
--------------------------------------------------------------------------------
/hash_table/hash_table.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include // abs
3 | #include
4 | #include
5 | #include "hash_object.h"
6 |
7 | #ifndef PROJECT_HASH_TABLE_H
8 | #define PROJECT_HASH_TABLE_H
9 |
10 | namespace jw {
11 | class HashTable {
12 | public:
13 | explicit HashTable(const int size);
14 | ~HashTable();
15 | HashTable(const HashTable &) = delete;
16 | HashTable &operator=(const HashTable &) = delete;
17 |
18 | // Add the given key and object to hash table. If key exists, update the
19 | // value.
20 | void Add(HashObject *object);
21 | // Returns true if the given key exists in the table
22 | bool Exists(const std::string key);
23 | // Returns the value associated with the given key, or NULL if it doesn't
24 | // exist
25 | const std::string Get(const std::string key);
26 | // Removes the value associated with key from the table.
27 | void Remove(const std::string key);
28 | // Outputs the content of the hash table for debugging purposes.
29 | void PrintDebug();
30 |
31 | private:
32 | int size_;
33 | HashObject *data_;
34 |
35 | int Hash(const std::string key);
36 | };
37 | }
38 |
39 | #endif // PROJECT_HASH_TABLE_H
40 |
--------------------------------------------------------------------------------
/hash_table/hash_tables_tests.cc:
--------------------------------------------------------------------------------
1 | #include "hash_tables_tests.h"
2 |
3 | void run_all_tests() {
4 | test_add_exists();
5 | test_probing();
6 | test_get();
7 | test_remove();
8 | }
9 |
10 | void test_add_exists() {
11 | jw::HashTable states(100);
12 |
13 | jw::HashObject tx;
14 | tx.SetKey("Texas");
15 | tx.SetValue("Austin");
16 |
17 | states.Add(&tx);
18 |
19 | assert(states.Exists("Texas"));
20 | }
21 |
22 | void test_probing() {
23 | // setting high load to force collisions
24 | jw::HashTable states(8);
25 |
26 | jw::HashObject tx;
27 | tx.SetKey("Texas");
28 | tx.SetValue("Austin");
29 |
30 | jw::HashObject ca;
31 | ca.SetKey("California");
32 | ca.SetValue("Sacramento");
33 |
34 | jw::HashObject nm;
35 | nm.SetKey("New Mexico");
36 | nm.SetValue("Santa Fe");
37 |
38 | jw::HashObject fl;
39 | fl.SetKey("Florida");
40 | fl.SetValue("Tallahassee");
41 |
42 | jw::HashObject oregon;
43 | oregon.SetKey("Oregon");
44 | oregon.SetValue("Salem");
45 |
46 | jw::HashObject wa;
47 | wa.SetKey("Washington");
48 | wa.SetValue("Olympia");
49 |
50 | jw::HashObject ut;
51 | ut.SetKey("Utah");
52 | ut.SetValue("Salt Lake City");
53 |
54 | jw::HashObject ny;
55 | ny.SetKey("New York");
56 | ny.SetValue("Albany");
57 |
58 | jw::HashObject mn;
59 | mn.SetKey("Minnesota");
60 | mn.SetValue("St. Paul");
61 |
62 | states.Add(&tx); // 1
63 | states.Add(&ca); // 0
64 | states.Add(&nm); //
65 | states.Add(&fl);
66 | states.Add(&oregon);
67 | states.Add(&wa);
68 | states.Add(&ut);
69 | states.Add(&ny);
70 | states.Add(&mn);
71 |
72 | // Texas:1
73 | // California:0
74 | // New Mexico:5
75 | // Florida:5
76 | // Oregon:4
77 | // Washington:0
78 | // Utah:6
79 | // New York:7
80 | // Minnesota:6
81 |
82 | // 0: California:Sacramento
83 | // 1: Texas:Austin
84 | // 2: Washington:Olympia
85 | // 3: New York:Albany
86 | // 4: Oregon:Salem
87 | // 5: New Mexico:Santa Fe
88 | // 6: Florida:Tallahassee
89 | // 7: Utah:Salt Lake City
90 |
91 | assert(states.Exists("California"));
92 | assert(states.Exists("New Mexico"));
93 | assert(states.Exists("Florida"));
94 | assert(!states.Exists("Minnesota")); // no room
95 | }
96 |
97 | void test_get() {
98 | jw::HashTable states(100);
99 |
100 | jw::HashObject tx;
101 | tx.SetKey("Texas");
102 | tx.SetValue("Austin");
103 |
104 | states.Add(&tx);
105 |
106 | assert(states.Get("Texas") == "Austin");
107 | }
108 |
109 | void test_remove() {
110 | jw::HashTable states(100);
111 |
112 | jw::HashObject tx;
113 | tx.SetKey("Texas");
114 | tx.SetValue("Austin");
115 |
116 | states.Add(&tx);
117 |
118 | assert(states.Exists("Texas"));
119 |
120 | states.Remove("Texas");
121 |
122 | assert(!states.Exists("Texas"));
123 | }
--------------------------------------------------------------------------------
/hash_table/hash_tables_tests.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "hash_table.h"
3 |
4 | #ifndef PROJECT_HASH_TABLES_TESTS_H
5 | #define PROJECT_HASH_TABLES_TESTS_H
6 |
7 | void run_all_tests();
8 |
9 | void test_add_exists();
10 | void test_probing();
11 | void test_get();
12 | void test_remove();
13 |
14 | #endif // PROJECT_HASH_TABLES_TESTS_H
15 |
--------------------------------------------------------------------------------
/hash_table/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "hash_table.cc"
3 | #include "hash_table.h"
4 | #include "hash_tables_tests.cc"
5 | #include "hash_tables_tests.h"
6 |
7 | void stdlib_experiments();
8 |
9 | int main(int argc, char *argv[]) {
10 | run_all_tests();
11 | //stdlib_experiments();
12 |
13 | return EXIT_SUCCESS;
14 | }
15 |
16 | void stdlib_experiments() {
17 | std::unordered_map states;
18 |
19 | states["Texas"] = "Austin";
20 | states["Florida"] = "Tallahassee";
21 | states["Washington"] = "Olympia";
22 |
23 | for (auto it = states.begin(); it != states.end(); ++it)
24 | std::cout << "The capital of " << it->first << " is " << it->second << std::endl;
25 |
26 | auto iter = states.find("Oregon");
27 | if (iter == states.end()) {
28 | std::cout << "Oregon not found" << std::endl;
29 | }
30 |
31 | std::cout << "Bucket count: " << states.bucket_count() << std::endl;
32 |
33 | auto count = states.bucket_count();
34 | for (auto i = 0; i < count; ++i) {
35 | std::cout << "Size of bucket " << i << ": " << states.bucket_size(i) << std::endl;
36 | }
37 | }
--------------------------------------------------------------------------------
/lib/googletest/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This file contains a list of people who've made non-trivial
2 | # contribution to the Google C++ Testing Framework project. People
3 | # who commit code to the project are encouraged to add their names
4 | # here. Please keep the list sorted by first names.
5 |
6 | Ajay Joshi
7 | Balázs Dán
8 | Bharat Mediratta
9 | Chandler Carruth
10 | Chris Prince
11 | Chris Taylor
12 | Dan Egnor
13 | Eric Roman
14 | Hady Zalek
15 | Jeffrey Yasskin
16 | Jói Sigurðsson
17 | Keir Mierle
18 | Keith Ray
19 | Kenton Varda
20 | Manuel Klimek
21 | Markus Heule
22 | Mika Raento
23 | Miklós Fazekas
24 | Pasi Valminen
25 | Patrick Hanna
26 | Patrick Riley
27 | Peter Kaminski
28 | Preston Jackson
29 | Rainer Klaffenboeck
30 | Russ Cox
31 | Russ Rufer
32 | Sean Mcafee
33 | Sigurður Ásgeirsson
34 | Tracy Bialik
35 | Vadim Berman
36 | Vlad Losev
37 | Zhanyong Wan
38 |
--------------------------------------------------------------------------------
/lib/googletest/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2008, Google Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/lib/googletest/build-aux/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwasham/practice-cpp/c46a7d2924231ec75fccbb9a395e3ae75239f446/lib/googletest/build-aux/.keep
--------------------------------------------------------------------------------
/lib/googletest/codegear/gtest.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {c1d923e0-6cba-4332-9b6f-3420acbf5091}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | Default.Personality
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/lib/googletest/codegear/gtest_all.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: Josh Kelley (joshkel@gmail.com)
31 | //
32 | // Google C++ Testing Framework (Google Test)
33 | //
34 | // C++Builder's IDE cannot build a static library from files with hyphens
35 | // in their name. See http://qc.codegear.com/wc/qcmain.aspx?d=70977 .
36 | // This file serves as a workaround.
37 |
38 | #include "src/gtest-all.cc"
39 |
--------------------------------------------------------------------------------
/lib/googletest/codegear/gtest_link.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: Josh Kelley (joshkel@gmail.com)
31 | //
32 | // Google C++ Testing Framework (Google Test)
33 | //
34 | // Links gtest.lib and gtest_main.lib into the current project in C++Builder.
35 | // This means that these libraries can't be renamed, but it's the only way to
36 | // ensure that Debug versus Release test builds are linked against the
37 | // appropriate Debug or Release build of the libraries.
38 |
39 | #pragma link "gtest.lib"
40 | #pragma link "gtest_main.lib"
41 |
--------------------------------------------------------------------------------
/lib/googletest/configure.ac:
--------------------------------------------------------------------------------
1 | m4_include(m4/acx_pthread.m4)
2 |
3 | # At this point, the Xcode project assumes the version string will be three
4 | # integers separated by periods and surrounded by square brackets (e.g.
5 | # "[1.0.1]"). It also asumes that there won't be any closing parenthesis
6 | # between "AC_INIT(" and the closing ")" including comments and strings.
7 | AC_INIT([Google C++ Testing Framework],
8 | [1.7.0],
9 | [googletestframework@googlegroups.com],
10 | [gtest])
11 |
12 | # Provide various options to initialize the Autoconf and configure processes.
13 | AC_PREREQ([2.59])
14 | AC_CONFIG_SRCDIR([./LICENSE])
15 | AC_CONFIG_MACRO_DIR([m4])
16 | AC_CONFIG_AUX_DIR([build-aux])
17 | AC_CONFIG_HEADERS([build-aux/config.h])
18 | AC_CONFIG_FILES([Makefile])
19 | AC_CONFIG_FILES([scripts/gtest-config], [chmod +x scripts/gtest-config])
20 |
21 | # Initialize Automake with various options. We require at least v1.9, prevent
22 | # pedantic complaints about package files, and enable various distribution
23 | # targets.
24 | AM_INIT_AUTOMAKE([1.9 dist-bzip2 dist-zip foreign subdir-objects])
25 |
26 | # Check for programs used in building Google Test.
27 | AC_PROG_CC
28 | AC_PROG_CXX
29 | AC_LANG([C++])
30 | AC_PROG_LIBTOOL
31 |
32 | # TODO(chandlerc@google.com): Currently we aren't running the Python tests
33 | # against the interpreter detected by AM_PATH_PYTHON, and so we condition
34 | # HAVE_PYTHON by requiring "python" to be in the PATH, and that interpreter's
35 | # version to be >= 2.3. This will allow the scripts to use a "/usr/bin/env"
36 | # hashbang.
37 | PYTHON= # We *do not* allow the user to specify a python interpreter
38 | AC_PATH_PROG([PYTHON],[python],[:])
39 | AS_IF([test "$PYTHON" != ":"],
40 | [AM_PYTHON_CHECK_VERSION([$PYTHON],[2.3],[:],[PYTHON=":"])])
41 | AM_CONDITIONAL([HAVE_PYTHON],[test "$PYTHON" != ":"])
42 |
43 | # Configure pthreads.
44 | AC_ARG_WITH([pthreads],
45 | [AS_HELP_STRING([--with-pthreads],
46 | [use pthreads (default is yes)])],
47 | [with_pthreads=$withval],
48 | [with_pthreads=check])
49 |
50 | have_pthreads=no
51 | AS_IF([test "x$with_pthreads" != "xno"],
52 | [ACX_PTHREAD(
53 | [],
54 | [AS_IF([test "x$with_pthreads" != "xcheck"],
55 | [AC_MSG_FAILURE(
56 | [--with-pthreads was specified, but unable to be used])])])
57 | have_pthreads="$acx_pthread_ok"])
58 | AM_CONDITIONAL([HAVE_PTHREADS],[test "x$have_pthreads" = "xyes"])
59 | AC_SUBST(PTHREAD_CFLAGS)
60 | AC_SUBST(PTHREAD_LIBS)
61 |
62 | # TODO(chandlerc@google.com) Check for the necessary system headers.
63 |
64 | # TODO(chandlerc@google.com) Check the types, structures, and other compiler
65 | # and architecture characteristics.
66 |
67 | # Output the generated files. No further autoconf macros may be used.
68 | AC_OUTPUT
69 |
--------------------------------------------------------------------------------
/lib/googletest/docs/Documentation.md:
--------------------------------------------------------------------------------
1 | This page lists all documentation wiki pages for Google Test **(the SVN trunk version)**
2 | -- **if you use a released version of Google Test, please read the
3 | documentation for that specific version instead.**
4 |
5 | * [Primer](Primer.md) -- Start here if you are new to Google Test.
6 | * [Samples](Samples.md) -- learn from examples.
7 | * [AdvancedGuide](AdvancedGuide.md) -- learn more about Google Test.
8 | * [XcodeGuide](XcodeGuide.md) -- how to use Google Test in Xcode on Mac.
9 | * [Frequently-Asked Questions](FAQ.md) -- check here before asking a question on the mailing list.
10 |
11 | To contribute code to Google Test, read:
12 |
13 | * [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
14 | * [PumpManual](PumpManual.md) -- how we generate some of Google Test's source files.
--------------------------------------------------------------------------------
/lib/googletest/docs/Samples.md:
--------------------------------------------------------------------------------
1 | If you're like us, you'd like to look at some Google Test sample code. The
2 | [samples folder](../samples) has a number of well-commented samples showing how to use a
3 | variety of Google Test features.
4 |
5 | * [Sample #1](../samples/sample1_unittest.cc) shows the basic steps of using Google Test to test C++ functions.
6 | * [Sample #2](../samples/sample2_unittest.cc) shows a more complex unit test for a class with multiple member functions.
7 | * [Sample #3](../samples/sample3_unittest.cc) uses a test fixture.
8 | * [Sample #4](../samples/sample4_unittest.cc) is another basic example of using Google Test.
9 | * [Sample #5](../samples/sample5_unittest.cc) teaches how to reuse a test fixture in multiple test cases by deriving sub-fixtures from it.
10 | * [Sample #6](../samples/sample6_unittest.cc) demonstrates type-parameterized tests.
11 | * [Sample #7](../samples/sample7_unittest.cc) teaches the basics of value-parameterized tests.
12 | * [Sample #8](../samples/sample8_unittest.cc) shows using `Combine()` in value-parameterized tests.
13 | * [Sample #9](../samples/sample9_unittest.cc) shows use of the listener API to modify Google Test's console output and the use of its reflection API to inspect test results.
14 | * [Sample #10](../samples/sample10_unittest.cc) shows use of the listener API to implement a primitive memory leak checker.
15 |
--------------------------------------------------------------------------------
/lib/googletest/docs/V1_5_Documentation.md:
--------------------------------------------------------------------------------
1 | This page lists all official documentation wiki pages for Google Test **1.5.0** -- **if you use a different version of Google Test, make sure to read the documentation for that version instead.**
2 |
3 | * [Primer](V1_5_Primer.md) -- Start here if you are new to Google Test.
4 | * [Samples](Samples.md) -- learn from examples.
5 | * [AdvancedGuide](V1_5_AdvancedGuide.md) -- learn more about Google Test.
6 | * [XcodeGuide](V1_5_XcodeGuide.md) -- how to use Google Test in Xcode on Mac.
7 | * [Frequently-Asked Questions](V1_5_FAQ.md) -- check here before asking a question on the mailing list.
8 |
9 | To contribute code to Google Test, read:
10 |
11 | * DevGuide -- read this _before_ writing your first patch.
12 | * [PumpManual](V1_5_PumpManual.md) -- how we generate some of Google Test's source files.
--------------------------------------------------------------------------------
/lib/googletest/docs/V1_6_Documentation.md:
--------------------------------------------------------------------------------
1 | This page lists all documentation wiki pages for Google Test **1.6**
2 | -- **if you use a released version of Google Test, please read the
3 | documentation for that specific version instead.**
4 |
5 | * [Primer](V1_6_Primer.md) -- Start here if you are new to Google Test.
6 | * [Samples](V1_6_Samples.md) -- learn from examples.
7 | * [AdvancedGuide](V1_6_AdvancedGuide.md) -- learn more about Google Test.
8 | * [XcodeGuide](V1_6_XcodeGuide.md) -- how to use Google Test in Xcode on Mac.
9 | * [Frequently-Asked Questions](V1_6_FAQ.md) -- check here before asking a question on the mailing list.
10 |
11 | To contribute code to Google Test, read:
12 |
13 | * [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
14 | * [PumpManual](V1_6_PumpManual.md) -- how we generate some of Google Test's source files.
--------------------------------------------------------------------------------
/lib/googletest/docs/V1_6_Samples.md:
--------------------------------------------------------------------------------
1 | If you're like us, you'd like to look at some Google Test sample code. The
2 | [samples folder](../samples) has a number of well-commented samples showing how to use a
3 | variety of Google Test features.
4 |
5 | * [Sample #1](../samples/sample1_unittest.cc) shows the basic steps of using Google Test to test C++ functions.
6 | * [Sample #2](../samples/sample2_unittest.cc) shows a more complex unit test for a class with multiple member functions.
7 | * [Sample #3](../samples/sample3_unittest.cc) uses a test fixture.
8 | * [Sample #4](../samples/sample4_unittest.cc) is another basic example of using Google Test.
9 | * [Sample #5](../samples/sample5_unittest.cc) teaches how to reuse a test fixture in multiple test cases by deriving sub-fixtures from it.
10 | * [Sample #6](../samples/sample6_unittest.cc) demonstrates type-parameterized tests.
11 | * [Sample #7](../samples/sample7_unittest.cc) teaches the basics of value-parameterized tests.
12 | * [Sample #8](../samples/sample8_unittest.cc) shows using `Combine()` in value-parameterized tests.
13 | * [Sample #9](../samples/sample9_unittest.cc) shows use of the listener API to modify Google Test's console output and the use of its reflection API to inspect test results.
14 | * [Sample #10](../samples/sample10_unittest.cc) shows use of the listener API to implement a primitive memory leak checker.
15 |
--------------------------------------------------------------------------------
/lib/googletest/docs/V1_7_Documentation.md:
--------------------------------------------------------------------------------
1 | This page lists all documentation wiki pages for Google Test **(the SVN trunk version)**
2 | -- **if you use a released version of Google Test, please read the
3 | documentation for that specific version instead.**
4 |
5 | * [Primer](V1_7_Primer.md) -- Start here if you are new to Google Test.
6 | * [Samples](V1_7_Samples.md) -- learn from examples.
7 | * [AdvancedGuide](V1_7_AdvancedGuide.md) -- learn more about Google Test.
8 | * [XcodeGuide](V1_7_XcodeGuide.md) -- how to use Google Test in Xcode on Mac.
9 | * [Frequently-Asked Questions](V1_7_FAQ.md) -- check here before asking a question on the mailing list.
10 |
11 | To contribute code to Google Test, read:
12 |
13 | * [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
14 | * [PumpManual](V1_7_PumpManual.md) -- how we generate some of Google Test's source files.
--------------------------------------------------------------------------------
/lib/googletest/docs/V1_7_Samples.md:
--------------------------------------------------------------------------------
1 | If you're like us, you'd like to look at some Google Test sample code. The
2 | [samples folder](../samples) has a number of well-commented samples showing how to use a
3 | variety of Google Test features.
4 |
5 | * [Sample #1](../samples/sample1_unittest.cc) shows the basic steps of using Google Test to test C++ functions.
6 | * [Sample #2](../samples/sample2_unittest.cc) shows a more complex unit test for a class with multiple member functions.
7 | * [Sample #3](../samples/sample3_unittest.cc) uses a test fixture.
8 | * [Sample #4](../samples/sample4_unittest.cc) is another basic example of using Google Test.
9 | * [Sample #5](../samples/sample5_unittest.cc) teaches how to reuse a test fixture in multiple test cases by deriving sub-fixtures from it.
10 | * [Sample #6](../samples/sample6_unittest.cc) demonstrates type-parameterized tests.
11 | * [Sample #7](../samples/sample7_unittest.cc) teaches the basics of value-parameterized tests.
12 | * [Sample #8](../samples/sample8_unittest.cc) shows using `Combine()` in value-parameterized tests.
13 | * [Sample #9](../samples/sample9_unittest.cc) shows use of the listener API to modify Google Test's console output and the use of its reflection API to inspect test results.
14 | * [Sample #10](../samples/sample10_unittest.cc) shows use of the listener API to implement a primitive memory leak checker.
15 |
--------------------------------------------------------------------------------
/lib/googletest/include/gtest/gtest_prod.h:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 | //
32 | // Google C++ Testing Framework definitions useful in production code.
33 |
34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_
35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_
36 |
37 | // When you need to test the private or protected members of a class,
38 | // use the FRIEND_TEST macro to declare your tests as friends of the
39 | // class. For example:
40 | //
41 | // class MyClass {
42 | // private:
43 | // void MyMethod();
44 | // FRIEND_TEST(MyClassTest, MyMethod);
45 | // };
46 | //
47 | // class MyClassTest : public testing::Test {
48 | // // ...
49 | // };
50 | //
51 | // TEST_F(MyClassTest, MyMethod) {
52 | // // Can call MyClass::MyMethod() here.
53 | // }
54 |
55 | #define FRIEND_TEST(test_case_name, test_name)\
56 | friend class test_case_name##_##test_name##_Test
57 |
58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_
59 |
--------------------------------------------------------------------------------
/lib/googletest/include/gtest/internal/custom/gtest-port.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Injection point for custom user configurations.
31 | // The following macros can be defined:
32 | //
33 | // Flag related macros:
34 | // GTEST_FLAG(flag_name)
35 | // GTEST_USE_OWN_FLAGFILE_FLAG_ - Define to 0 when the system provides its
36 | // own flagfile flag parsing.
37 | // GTEST_DECLARE_bool_(name)
38 | // GTEST_DECLARE_int32_(name)
39 | // GTEST_DECLARE_string_(name)
40 | // GTEST_DEFINE_bool_(name, default_val, doc)
41 | // GTEST_DEFINE_int32_(name, default_val, doc)
42 | // GTEST_DEFINE_string_(name, default_val, doc)
43 | //
44 | // Test filtering:
45 | // GTEST_TEST_FILTER_ENV_VAR_ - The name of an environment variable that
46 | // will be used if --GTEST_FLAG(test_filter)
47 | // is not provided.
48 | //
49 | // Logging:
50 | // GTEST_LOG_(severity)
51 | // GTEST_CHECK_(condition)
52 | // Functions LogToStderr() and FlushInfoLog() have to be provided too.
53 | //
54 | // Threading:
55 | // GTEST_HAS_NOTIFICATION_ - Enabled if Notification is already provided.
56 | // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Enabled if Mutex and ThreadLocal are
57 | // already provided.
58 | // Must also provide GTEST_DECLARE_STATIC_MUTEX_(mutex) and
59 | // GTEST_DEFINE_STATIC_MUTEX_(mutex)
60 | //
61 | // GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
62 | // GTEST_LOCK_EXCLUDED_(locks)
63 | //
64 | // ** Custom implementation starts here **
65 |
66 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
67 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
68 |
69 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
70 |
--------------------------------------------------------------------------------
/lib/googletest/include/gtest/internal/custom/gtest-printers.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // This file provides an injection point for custom printers in a local
31 | // installation of gTest.
32 | // It will be included from gtest-printers.h and the overrides in this file
33 | // will be visible to everyone.
34 | // See documentation at gtest/gtest-printers.h for details on how to define a
35 | // custom printer.
36 | //
37 | // ** Custom implementation starts here **
38 |
39 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
40 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
41 |
42 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
43 |
--------------------------------------------------------------------------------
/lib/googletest/include/gtest/internal/custom/gtest.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Injection point for custom user configurations.
31 | // The following macros can be defined:
32 | //
33 | // GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of
34 | // OsStackTraceGetterInterface.
35 | //
36 | // ** Custom implementation starts here **
37 |
38 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
39 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
40 |
41 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
42 |
--------------------------------------------------------------------------------
/lib/googletest/include/gtest/internal/gtest-port-arch.h:
--------------------------------------------------------------------------------
1 | // Copyright 2015, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // The Google C++ Testing Framework (Google Test)
31 | //
32 | // This header file defines the GTEST_OS_* macro.
33 | // It is separate from gtest-port.h so that custom/gtest-port.h can include it.
34 |
35 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
36 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
37 |
38 | // Determines the platform on which Google Test is compiled.
39 | #ifdef __CYGWIN__
40 | # define GTEST_OS_CYGWIN 1
41 | #elif defined __SYMBIAN32__
42 | # define GTEST_OS_SYMBIAN 1
43 | #elif defined _WIN32
44 | # define GTEST_OS_WINDOWS 1
45 | # ifdef _WIN32_WCE
46 | # define GTEST_OS_WINDOWS_MOBILE 1
47 | # elif defined(__MINGW__) || defined(__MINGW32__)
48 | # define GTEST_OS_WINDOWS_MINGW 1
49 | # elif defined(WINAPI_FAMILY)
50 | # include
51 | # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
52 | # define GTEST_OS_WINDOWS_DESKTOP 1
53 | # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
54 | # define GTEST_OS_WINDOWS_PHONE 1
55 | # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
56 | # define GTEST_OS_WINDOWS_RT 1
57 | # else
58 | // WINAPI_FAMILY defined but no known partition matched.
59 | // Default to desktop.
60 | # define GTEST_OS_WINDOWS_DESKTOP 1
61 | # endif
62 | # else
63 | # define GTEST_OS_WINDOWS_DESKTOP 1
64 | # endif // _WIN32_WCE
65 | #elif defined __APPLE__
66 | # define GTEST_OS_MAC 1
67 | # if TARGET_OS_IPHONE
68 | # define GTEST_OS_IOS 1
69 | # endif
70 | #elif defined __FreeBSD__
71 | # define GTEST_OS_FREEBSD 1
72 | #elif defined __linux__
73 | # define GTEST_OS_LINUX 1
74 | # if defined __ANDROID__
75 | # define GTEST_OS_LINUX_ANDROID 1
76 | # endif
77 | #elif defined __MVS__
78 | # define GTEST_OS_ZOS 1
79 | #elif defined(__sun) && defined(__SVR4)
80 | # define GTEST_OS_SOLARIS 1
81 | #elif defined(_AIX)
82 | # define GTEST_OS_AIX 1
83 | #elif defined(__hpux)
84 | # define GTEST_OS_HPUX 1
85 | #elif defined __native_client__
86 | # define GTEST_OS_NACL 1
87 | #elif defined __OpenBSD__
88 | # define GTEST_OS_OPENBSD 1
89 | #elif defined __QNX__
90 | # define GTEST_OS_QNX 1
91 | #endif // __CYGWIN__
92 |
93 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
94 |
--------------------------------------------------------------------------------
/lib/googletest/m4/gtest.m4:
--------------------------------------------------------------------------------
1 | dnl GTEST_LIB_CHECK([minimum version [,
2 | dnl action if found [,action if not found]]])
3 | dnl
4 | dnl Check for the presence of the Google Test library, optionally at a minimum
5 | dnl version, and indicate a viable version with the HAVE_GTEST flag. It defines
6 | dnl standard variables for substitution including GTEST_CPPFLAGS,
7 | dnl GTEST_CXXFLAGS, GTEST_LDFLAGS, and GTEST_LIBS. It also defines
8 | dnl GTEST_VERSION as the version of Google Test found. Finally, it provides
9 | dnl optional custom action slots in the event GTEST is found or not.
10 | AC_DEFUN([GTEST_LIB_CHECK],
11 | [
12 | dnl Provide a flag to enable or disable Google Test usage.
13 | AC_ARG_ENABLE([gtest],
14 | [AS_HELP_STRING([--enable-gtest],
15 | [Enable tests using the Google C++ Testing Framework.
16 | (Default is enabled.)])],
17 | [],
18 | [enable_gtest=])
19 | AC_ARG_VAR([GTEST_CONFIG],
20 | [The exact path of Google Test's 'gtest-config' script.])
21 | AC_ARG_VAR([GTEST_CPPFLAGS],
22 | [C-like preprocessor flags for Google Test.])
23 | AC_ARG_VAR([GTEST_CXXFLAGS],
24 | [C++ compile flags for Google Test.])
25 | AC_ARG_VAR([GTEST_LDFLAGS],
26 | [Linker path and option flags for Google Test.])
27 | AC_ARG_VAR([GTEST_LIBS],
28 | [Library linking flags for Google Test.])
29 | AC_ARG_VAR([GTEST_VERSION],
30 | [The version of Google Test available.])
31 | HAVE_GTEST="no"
32 | AS_IF([test "x${enable_gtest}" != "xno"],
33 | [AC_MSG_CHECKING([for 'gtest-config'])
34 | AS_IF([test "x${enable_gtest}" != "xyes"],
35 | [AS_IF([test -x "${enable_gtest}/scripts/gtest-config"],
36 | [GTEST_CONFIG="${enable_gtest}/scripts/gtest-config"],
37 | [GTEST_CONFIG="${enable_gtest}/bin/gtest-config"])
38 | AS_IF([test -x "${GTEST_CONFIG}"], [],
39 | [AC_MSG_RESULT([no])
40 | AC_MSG_ERROR([dnl
41 | Unable to locate either a built or installed Google Test.
42 | The specific location '${enable_gtest}' was provided for a built or installed
43 | Google Test, but no 'gtest-config' script could be found at this location.])
44 | ])],
45 | [AC_PATH_PROG([GTEST_CONFIG], [gtest-config])])
46 | AS_IF([test -x "${GTEST_CONFIG}"],
47 | [AC_MSG_RESULT([${GTEST_CONFIG}])
48 | m4_ifval([$1],
49 | [_gtest_min_version="--min-version=$1"
50 | AC_MSG_CHECKING([for Google Test at least version >= $1])],
51 | [_gtest_min_version="--min-version=0"
52 | AC_MSG_CHECKING([for Google Test])])
53 | AS_IF([${GTEST_CONFIG} ${_gtest_min_version}],
54 | [AC_MSG_RESULT([yes])
55 | HAVE_GTEST='yes'],
56 | [AC_MSG_RESULT([no])])],
57 | [AC_MSG_RESULT([no])])
58 | AS_IF([test "x${HAVE_GTEST}" = "xyes"],
59 | [GTEST_CPPFLAGS=`${GTEST_CONFIG} --cppflags`
60 | GTEST_CXXFLAGS=`${GTEST_CONFIG} --cxxflags`
61 | GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`
62 | GTEST_LIBS=`${GTEST_CONFIG} --libs`
63 | GTEST_VERSION=`${GTEST_CONFIG} --version`
64 | AC_DEFINE([HAVE_GTEST],[1],[Defined when Google Test is available.])],
65 | [AS_IF([test "x${enable_gtest}" = "xyes"],
66 | [AC_MSG_ERROR([dnl
67 | Google Test was enabled, but no viable version could be found.])
68 | ])])])
69 | AC_SUBST([HAVE_GTEST])
70 | AM_CONDITIONAL([HAVE_GTEST],[test "x$HAVE_GTEST" = "xyes"])
71 | AS_IF([test "x$HAVE_GTEST" = "xyes"],
72 | [m4_ifval([$2], [$2])],
73 | [m4_ifval([$3], [$3])])
74 | ])
75 |
--------------------------------------------------------------------------------
/lib/googletest/make/Makefile:
--------------------------------------------------------------------------------
1 | # A sample Makefile for building Google Test and using it in user
2 | # tests. Please tweak it to suit your environment and project. You
3 | # may want to move it to your project's root directory.
4 | #
5 | # SYNOPSIS:
6 | #
7 | # make [all] - makes everything.
8 | # make TARGET - makes the given target.
9 | # make clean - removes all files generated by make.
10 |
11 | # Please tweak the following variable definitions as needed by your
12 | # project, except GTEST_HEADERS, which you can use in your own targets
13 | # but shouldn't modify.
14 |
15 | # Points to the root of Google Test, relative to where this file is.
16 | # Remember to tweak this if you move this file.
17 | GTEST_DIR = ..
18 |
19 | # Where to find user code.
20 | USER_DIR = ../samples
21 |
22 | # Flags passed to the preprocessor.
23 | # Set Google Test's header directory as a system directory, such that
24 | # the compiler doesn't generate warnings in Google Test headers.
25 | CPPFLAGS += -isystem $(GTEST_DIR)/include
26 |
27 | # Flags passed to the C++ compiler.
28 | CXXFLAGS += -g -Wall -Wextra -pthread
29 |
30 | # All tests produced by this Makefile. Remember to add new tests you
31 | # created to the list.
32 | TESTS = sample1_unittest
33 |
34 | # All Google Test headers. Usually you shouldn't change this
35 | # definition.
36 | GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
37 | $(GTEST_DIR)/include/gtest/internal/*.h
38 |
39 | # House-keeping build targets.
40 |
41 | all : $(TESTS)
42 |
43 | clean :
44 | rm -f $(TESTS) gtest.a gtest_main.a *.o
45 |
46 | # Builds gtest.a and gtest_main.a.
47 |
48 | # Usually you shouldn't tweak such internal variables, indicated by a
49 | # trailing _.
50 | GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
51 |
52 | # For simplicity and to avoid depending on Google Test's
53 | # implementation details, the dependencies specified below are
54 | # conservative and not optimized. This is fine as Google Test
55 | # compiles fast and for ordinary users its source rarely changes.
56 | gtest-all.o : $(GTEST_SRCS_)
57 | $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
58 | $(GTEST_DIR)/src/gtest-all.cc
59 |
60 | gtest_main.o : $(GTEST_SRCS_)
61 | $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
62 | $(GTEST_DIR)/src/gtest_main.cc
63 |
64 | gtest.a : gtest-all.o
65 | $(AR) $(ARFLAGS) $@ $^
66 |
67 | gtest_main.a : gtest-all.o gtest_main.o
68 | $(AR) $(ARFLAGS) $@ $^
69 |
70 | # Builds a sample test. A test should link with either gtest.a or
71 | # gtest_main.a, depending on whether it defines its own main()
72 | # function.
73 |
74 | sample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS)
75 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc
76 |
77 | sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \
78 | $(USER_DIR)/sample1.h $(GTEST_HEADERS)
79 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
80 |
81 | sample1_unittest : sample1.o sample1_unittest.o gtest_main.a
82 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
83 |
--------------------------------------------------------------------------------
/lib/googletest/msvc/gtest-md.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 8.00
2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-md", "gtest-md.vcproj", "{C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}"
3 | ProjectSection(ProjectDependencies) = postProject
4 | EndProjectSection
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main-md", "gtest_main-md.vcproj", "{3AF54C8A-10BF-4332-9147-F68ED9862033}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | EndProjectSection
9 | EndProject
10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_prod_test-md", "gtest_prod_test-md.vcproj", "{24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}"
11 | ProjectSection(ProjectDependencies) = postProject
12 | EndProjectSection
13 | EndProject
14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_unittest-md", "gtest_unittest-md.vcproj", "{4D9FDFB5-986A-4139-823C-F4EE0ED481A2}"
15 | ProjectSection(ProjectDependencies) = postProject
16 | EndProjectSection
17 | EndProject
18 | Global
19 | GlobalSection(SolutionConfiguration) = preSolution
20 | Debug = Debug
21 | Release = Release
22 | EndGlobalSection
23 | GlobalSection(ProjectConfiguration) = postSolution
24 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Debug.ActiveCfg = Debug|Win32
25 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Debug.Build.0 = Debug|Win32
26 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Release.ActiveCfg = Release|Win32
27 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Release.Build.0 = Release|Win32
28 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Debug.ActiveCfg = Debug|Win32
29 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Debug.Build.0 = Debug|Win32
30 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Release.ActiveCfg = Release|Win32
31 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Release.Build.0 = Release|Win32
32 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Debug.ActiveCfg = Debug|Win32
33 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Debug.Build.0 = Debug|Win32
34 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Release.ActiveCfg = Release|Win32
35 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Release.Build.0 = Release|Win32
36 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Debug.ActiveCfg = Debug|Win32
37 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Debug.Build.0 = Debug|Win32
38 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Release.ActiveCfg = Release|Win32
39 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Release.Build.0 = Release|Win32
40 | EndGlobalSection
41 | GlobalSection(ExtensibilityGlobals) = postSolution
42 | EndGlobalSection
43 | GlobalSection(ExtensibilityAddIns) = postSolution
44 | EndGlobalSection
45 | EndGlobal
46 |
--------------------------------------------------------------------------------
/lib/googletest/msvc/gtest.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 8.00
2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "gtest.vcproj", "{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}"
3 | ProjectSection(ProjectDependencies) = postProject
4 | EndProjectSection
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main", "gtest_main.vcproj", "{3AF54C8A-10BF-4332-9147-F68ED9862032}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | EndProjectSection
9 | EndProject
10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_unittest", "gtest_unittest.vcproj", "{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}"
11 | ProjectSection(ProjectDependencies) = postProject
12 | EndProjectSection
13 | EndProject
14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_prod_test", "gtest_prod_test.vcproj", "{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}"
15 | ProjectSection(ProjectDependencies) = postProject
16 | EndProjectSection
17 | EndProject
18 | Global
19 | GlobalSection(SolutionConfiguration) = preSolution
20 | Debug = Debug
21 | Release = Release
22 | EndGlobalSection
23 | GlobalSection(ProjectConfiguration) = postSolution
24 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.ActiveCfg = Debug|Win32
25 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.Build.0 = Debug|Win32
26 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.ActiveCfg = Release|Win32
27 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.Build.0 = Release|Win32
28 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.ActiveCfg = Debug|Win32
29 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.Build.0 = Debug|Win32
30 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.ActiveCfg = Release|Win32
31 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.Build.0 = Release|Win32
32 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.ActiveCfg = Debug|Win32
33 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.Build.0 = Debug|Win32
34 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.ActiveCfg = Release|Win32
35 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.Build.0 = Release|Win32
36 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.ActiveCfg = Debug|Win32
37 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.Build.0 = Debug|Win32
38 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.ActiveCfg = Release|Win32
39 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.Build.0 = Release|Win32
40 | EndGlobalSection
41 | GlobalSection(ExtensibilityGlobals) = postSolution
42 | EndGlobalSection
43 | GlobalSection(ExtensibilityAddIns) = postSolution
44 | EndGlobalSection
45 | EndGlobal
46 |
--------------------------------------------------------------------------------
/lib/googletest/msvc/gtest.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
13 |
20 |
31 |
33 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
55 |
62 |
70 |
72 |
75 |
77 |
79 |
81 |
83 |
85 |
87 |
89 |
91 |
93 |
94 |
95 |
96 |
97 |
98 |
102 |
104 |
106 |
109 |
110 |
112 |
115 |
116 |
117 |
118 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/lib/googletest/samples/sample1.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #include "sample1.h"
35 |
36 | // Returns n! (the factorial of n). For negative n, n! is defined to be 1.
37 | int Factorial(int n) {
38 | int result = 1;
39 | for (int i = 1; i <= n; i++) {
40 | result *= i;
41 | }
42 |
43 | return result;
44 | }
45 |
46 | // Returns true iff n is a prime number.
47 | bool IsPrime(int n) {
48 | // Trivial case 1: small numbers
49 | if (n <= 1) return false;
50 |
51 | // Trivial case 2: even numbers
52 | if (n % 2 == 0) return n == 2;
53 |
54 | // Now, we have that n is odd and n >= 3.
55 |
56 | // Try to divide n by every odd number i, starting from 3
57 | for (int i = 3; ; i += 2) {
58 | // We only have to try i up to the squre root of n
59 | if (i > n/i) break;
60 |
61 | // Now, we have i <= n/i < n.
62 | // If n is divisible by i, n is not prime.
63 | if (n % i == 0) return false;
64 | }
65 |
66 | // n has no integer factor in the range (1, n), and thus is prime.
67 | return true;
68 | }
69 |
--------------------------------------------------------------------------------
/lib/googletest/samples/sample1.h:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #ifndef GTEST_SAMPLES_SAMPLE1_H_
35 | #define GTEST_SAMPLES_SAMPLE1_H_
36 |
37 | // Returns n! (the factorial of n). For negative n, n! is defined to be 1.
38 | int Factorial(int n);
39 |
40 | // Returns true iff n is a prime number.
41 | bool IsPrime(int n);
42 |
43 | #endif // GTEST_SAMPLES_SAMPLE1_H_
44 |
--------------------------------------------------------------------------------
/lib/googletest/samples/sample2.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #include "sample2.h"
35 |
36 | #include
37 |
38 | // Clones a 0-terminated C string, allocating memory using new.
39 | const char* MyString::CloneCString(const char* a_c_string) {
40 | if (a_c_string == NULL) return NULL;
41 |
42 | const size_t len = strlen(a_c_string);
43 | char* const clone = new char[ len + 1 ];
44 | memcpy(clone, a_c_string, len + 1);
45 |
46 | return clone;
47 | }
48 |
49 | // Sets the 0-terminated C string this MyString object
50 | // represents.
51 | void MyString::Set(const char* a_c_string) {
52 | // Makes sure this works when c_string == c_string_
53 | const char* const temp = MyString::CloneCString(a_c_string);
54 | delete[] c_string_;
55 | c_string_ = temp;
56 | }
57 |
--------------------------------------------------------------------------------
/lib/googletest/samples/sample2.h:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #ifndef GTEST_SAMPLES_SAMPLE2_H_
35 | #define GTEST_SAMPLES_SAMPLE2_H_
36 |
37 | #include
38 |
39 |
40 | // A simple string class.
41 | class MyString {
42 | private:
43 | const char* c_string_;
44 | const MyString& operator=(const MyString& rhs);
45 |
46 | public:
47 | // Clones a 0-terminated C string, allocating memory using new.
48 | static const char* CloneCString(const char* a_c_string);
49 |
50 | ////////////////////////////////////////////////////////////
51 | //
52 | // C'tors
53 |
54 | // The default c'tor constructs a NULL string.
55 | MyString() : c_string_(NULL) {}
56 |
57 | // Constructs a MyString by cloning a 0-terminated C string.
58 | explicit MyString(const char* a_c_string) : c_string_(NULL) {
59 | Set(a_c_string);
60 | }
61 |
62 | // Copy c'tor
63 | MyString(const MyString& string) : c_string_(NULL) {
64 | Set(string.c_string_);
65 | }
66 |
67 | ////////////////////////////////////////////////////////////
68 | //
69 | // D'tor. MyString is intended to be a final class, so the d'tor
70 | // doesn't need to be virtual.
71 | ~MyString() { delete[] c_string_; }
72 |
73 | // Gets the 0-terminated C string this MyString object represents.
74 | const char* c_string() const { return c_string_; }
75 |
76 | size_t Length() const {
77 | return c_string_ == NULL ? 0 : strlen(c_string_);
78 | }
79 |
80 | // Sets the 0-terminated C string this MyString object represents.
81 | void Set(const char* c_string);
82 | };
83 |
84 |
85 | #endif // GTEST_SAMPLES_SAMPLE2_H_
86 |
--------------------------------------------------------------------------------
/lib/googletest/samples/sample4.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #include
35 |
36 | #include "sample4.h"
37 |
38 | // Returns the current counter value, and increments it.
39 | int Counter::Increment() {
40 | return counter_++;
41 | }
42 |
43 | // Prints the current counter value to STDOUT.
44 | void Counter::Print() const {
45 | printf("%d", counter_);
46 | }
47 |
--------------------------------------------------------------------------------
/lib/googletest/samples/sample4.h:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #ifndef GTEST_SAMPLES_SAMPLE4_H_
35 | #define GTEST_SAMPLES_SAMPLE4_H_
36 |
37 | // A simple monotonic counter.
38 | class Counter {
39 | private:
40 | int counter_;
41 |
42 | public:
43 | // Creates a counter that starts at 0.
44 | Counter() : counter_(0) {}
45 |
46 | // Returns the current counter value, and increments it.
47 | int Increment();
48 |
49 | // Prints the current counter value to STDOUT.
50 | void Print() const;
51 | };
52 |
53 | #endif // GTEST_SAMPLES_SAMPLE4_H_
54 |
--------------------------------------------------------------------------------
/lib/googletest/samples/sample4_unittest.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include "gtest/gtest.h"
33 | #include "sample4.h"
34 |
35 | // Tests the Increment() method.
36 | TEST(Counter, Increment) {
37 | Counter c;
38 |
39 | // EXPECT_EQ() evaluates its arguments exactly once, so they
40 | // can have side effects.
41 |
42 | EXPECT_EQ(0, c.Increment());
43 | EXPECT_EQ(1, c.Increment());
44 | EXPECT_EQ(2, c.Increment());
45 | }
46 |
--------------------------------------------------------------------------------
/lib/googletest/scripts/common.py:
--------------------------------------------------------------------------------
1 | # Copyright 2013 Google Inc. All Rights Reserved.
2 | #
3 | # Redistribution and use in source and binary forms, with or without
4 | # modification, are permitted provided that the following conditions are
5 | # met:
6 | #
7 | # * Redistributions of source code must retain the above copyright
8 | # notice, this list of conditions and the following disclaimer.
9 | # * Redistributions in binary form must reproduce the above
10 | # copyright notice, this list of conditions and the following disclaimer
11 | # in the documentation and/or other materials provided with the
12 | # distribution.
13 | # * Neither the name of Google Inc. nor the names of its
14 | # contributors may be used to endorse or promote products derived from
15 | # this software without specific prior written permission.
16 | #
17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | """Shared utilities for writing scripts for Google Test/Mock."""
30 |
31 | __author__ = 'wan@google.com (Zhanyong Wan)'
32 |
33 |
34 | import os
35 | import re
36 |
37 |
38 | # Matches the line from 'svn info .' output that describes what SVN
39 | # path the current local directory corresponds to. For example, in
40 | # a googletest SVN workspace's trunk/test directory, the output will be:
41 | #
42 | # URL: https://googletest.googlecode.com/svn/trunk/test
43 | _SVN_INFO_URL_RE = re.compile(r'^URL: https://(\w+)\.googlecode\.com/svn(.*)')
44 |
45 |
46 | def GetCommandOutput(command):
47 | """Runs the shell command and returns its stdout as a list of lines."""
48 |
49 | f = os.popen(command, 'r')
50 | lines = [line.strip() for line in f.readlines()]
51 | f.close()
52 | return lines
53 |
54 |
55 | def GetSvnInfo():
56 | """Returns the project name and the current SVN workspace's root path."""
57 |
58 | for line in GetCommandOutput('svn info .'):
59 | m = _SVN_INFO_URL_RE.match(line)
60 | if m:
61 | project = m.group(1) # googletest or googlemock
62 | rel_path = m.group(2)
63 | root = os.path.realpath(rel_path.count('/') * '../')
64 | return project, root
65 |
66 | return None, None
67 |
68 |
69 | def GetSvnTrunk():
70 | """Returns the current SVN workspace's trunk root path."""
71 |
72 | _, root = GetSvnInfo()
73 | return root + '/trunk' if root else None
74 |
75 |
76 | def IsInGTestSvn():
77 | project, _ = GetSvnInfo()
78 | return project == 'googletest'
79 |
80 |
81 | def IsInGMockSvn():
82 | project, _ = GetSvnInfo()
83 | return project == 'googlemock'
84 |
--------------------------------------------------------------------------------
/lib/googletest/scripts/test/Makefile:
--------------------------------------------------------------------------------
1 | # A Makefile for fusing Google Test and building a sample test against it.
2 | #
3 | # SYNOPSIS:
4 | #
5 | # make [all] - makes everything.
6 | # make TARGET - makes the given target.
7 | # make check - makes everything and runs the built sample test.
8 | # make clean - removes all files generated by make.
9 |
10 | # Points to the root of fused Google Test, relative to where this file is.
11 | FUSED_GTEST_DIR = output
12 |
13 | # Paths to the fused gtest files.
14 | FUSED_GTEST_H = $(FUSED_GTEST_DIR)/gtest/gtest.h
15 | FUSED_GTEST_ALL_CC = $(FUSED_GTEST_DIR)/gtest/gtest-all.cc
16 |
17 | # Where to find the sample test.
18 | SAMPLE_DIR = ../../samples
19 |
20 | # Where to find gtest_main.cc.
21 | GTEST_MAIN_CC = ../../src/gtest_main.cc
22 |
23 | # Flags passed to the preprocessor.
24 | # We have no idea here whether pthreads is available in the system, so
25 | # disable its use.
26 | CPPFLAGS += -I$(FUSED_GTEST_DIR) -DGTEST_HAS_PTHREAD=0
27 |
28 | # Flags passed to the C++ compiler.
29 | CXXFLAGS += -g
30 |
31 | all : sample1_unittest
32 |
33 | check : all
34 | ./sample1_unittest
35 |
36 | clean :
37 | rm -rf $(FUSED_GTEST_DIR) sample1_unittest *.o
38 |
39 | $(FUSED_GTEST_H) :
40 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR)
41 |
42 | $(FUSED_GTEST_ALL_CC) :
43 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR)
44 |
45 | gtest-all.o : $(FUSED_GTEST_H) $(FUSED_GTEST_ALL_CC)
46 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FUSED_GTEST_DIR)/gtest/gtest-all.cc
47 |
48 | gtest_main.o : $(FUSED_GTEST_H) $(GTEST_MAIN_CC)
49 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(GTEST_MAIN_CC)
50 |
51 | sample1.o : $(SAMPLE_DIR)/sample1.cc $(SAMPLE_DIR)/sample1.h
52 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1.cc
53 |
54 | sample1_unittest.o : $(SAMPLE_DIR)/sample1_unittest.cc \
55 | $(SAMPLE_DIR)/sample1.h $(FUSED_GTEST_H)
56 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1_unittest.cc
57 |
58 | sample1_unittest : sample1.o sample1_unittest.o gtest-all.o gtest_main.o
59 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@
60 |
--------------------------------------------------------------------------------
/lib/googletest/scripts/upload_gtest.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # Copyright 2009, Google Inc.
4 | # All rights reserved.
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are
8 | # met:
9 | #
10 | # * Redistributions of source code must retain the above copyright
11 | # notice, this list of conditions and the following disclaimer.
12 | # * Redistributions in binary form must reproduce the above
13 | # copyright notice, this list of conditions and the following disclaimer
14 | # in the documentation and/or other materials provided with the
15 | # distribution.
16 | # * Neither the name of Google Inc. nor the names of its
17 | # contributors may be used to endorse or promote products derived from
18 | # this software without specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 | """upload_gtest.py v0.1.0 -- uploads a Google Test patch for review.
33 |
34 | This simple wrapper passes all command line flags and
35 | --cc=googletestframework@googlegroups.com to upload.py.
36 |
37 | USAGE: upload_gtest.py [options for upload.py]
38 | """
39 |
40 | __author__ = 'wan@google.com (Zhanyong Wan)'
41 |
42 | import os
43 | import sys
44 |
45 | CC_FLAG = '--cc='
46 | GTEST_GROUP = 'googletestframework@googlegroups.com'
47 |
48 |
49 | def main():
50 | # Finds the path to upload.py, assuming it is in the same directory
51 | # as this file.
52 | my_dir = os.path.dirname(os.path.abspath(__file__))
53 | upload_py_path = os.path.join(my_dir, 'upload.py')
54 |
55 | # Adds Google Test discussion group to the cc line if it's not there
56 | # already.
57 | upload_py_argv = [upload_py_path]
58 | found_cc_flag = False
59 | for arg in sys.argv[1:]:
60 | if arg.startswith(CC_FLAG):
61 | found_cc_flag = True
62 | cc_line = arg[len(CC_FLAG):]
63 | cc_list = [addr for addr in cc_line.split(',') if addr]
64 | if GTEST_GROUP not in cc_list:
65 | cc_list.append(GTEST_GROUP)
66 | upload_py_argv.append(CC_FLAG + ','.join(cc_list))
67 | else:
68 | upload_py_argv.append(arg)
69 |
70 | if not found_cc_flag:
71 | upload_py_argv.append(CC_FLAG + GTEST_GROUP)
72 |
73 | # Invokes upload.py with the modified command line flags.
74 | os.execv(upload_py_path, upload_py_argv)
75 |
76 |
77 | if __name__ == '__main__':
78 | main()
79 |
--------------------------------------------------------------------------------
/lib/googletest/src/gtest-all.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: mheule@google.com (Markus Heule)
31 | //
32 | // Google C++ Testing Framework (Google Test)
33 | //
34 | // Sometimes it's desirable to build Google Test by compiling a single file.
35 | // This file serves this purpose.
36 |
37 | // This line ensures that gtest.h can be compiled on its own, even
38 | // when it's fused.
39 | #include "gtest/gtest.h"
40 |
41 | // The following lines pull in the real gtest *.cc files.
42 | #include "src/gtest.cc"
43 | #include "src/gtest-death-test.cc"
44 | #include "src/gtest-filepath.cc"
45 | #include "src/gtest-port.cc"
46 | #include "src/gtest-printers.cc"
47 | #include "src/gtest-test-part.cc"
48 | #include "src/gtest-typed-test.cc"
49 |
--------------------------------------------------------------------------------
/lib/googletest/src/gtest_main.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | #include
31 |
32 | #include "gtest/gtest.h"
33 |
34 | GTEST_API_ int main(int argc, char **argv) {
35 | printf("Running main() from gtest_main.cc\n");
36 | testing::InitGoogleTest(&argc, argv);
37 | return RUN_ALL_TESTS();
38 | }
39 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest-param-test2_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: vladl@google.com (Vlad Losev)
31 | //
32 | // Tests for Google Test itself. This verifies that the basic constructs of
33 | // Google Test work.
34 |
35 | #include "gtest/gtest.h"
36 |
37 | #include "test/gtest-param-test_test.h"
38 |
39 | #if GTEST_HAS_PARAM_TEST
40 |
41 | using ::testing::Values;
42 | using ::testing::internal::ParamGenerator;
43 |
44 | // Tests that generators defined in a different translation unit
45 | // are functional. The test using extern_gen is defined
46 | // in gtest-param-test_test.cc.
47 | ParamGenerator extern_gen = Values(33);
48 |
49 | // Tests that a parameterized test case can be defined in one translation unit
50 | // and instantiated in another. The test is defined in gtest-param-test_test.cc
51 | // and ExternalInstantiationTest fixture class is defined in
52 | // gtest-param-test_test.h.
53 | INSTANTIATE_TEST_CASE_P(MultiplesOf33,
54 | ExternalInstantiationTest,
55 | Values(33, 66));
56 |
57 | // Tests that a parameterized test case can be instantiated
58 | // in multiple translation units. Another instantiation is defined
59 | // in gtest-param-test_test.cc and InstantiationInMultipleTranslaionUnitsTest
60 | // fixture is defined in gtest-param-test_test.h
61 | INSTANTIATE_TEST_CASE_P(Sequence2,
62 | InstantiationInMultipleTranslaionUnitsTest,
63 | Values(42*3, 42*4, 42*5));
64 |
65 | #endif // GTEST_HAS_PARAM_TEST
66 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest-param-test_test.h:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Authors: vladl@google.com (Vlad Losev)
31 | //
32 | // The Google C++ Testing Framework (Google Test)
33 | //
34 | // This header file provides classes and functions used internally
35 | // for testing Google Test itself.
36 |
37 | #ifndef GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
38 | #define GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
39 |
40 | #include "gtest/gtest.h"
41 |
42 | #if GTEST_HAS_PARAM_TEST
43 |
44 | // Test fixture for testing definition and instantiation of a test
45 | // in separate translation units.
46 | class ExternalInstantiationTest : public ::testing::TestWithParam {
47 | };
48 |
49 | // Test fixture for testing instantiation of a test in multiple
50 | // translation units.
51 | class InstantiationInMultipleTranslaionUnitsTest
52 | : public ::testing::TestWithParam {
53 | };
54 |
55 | #endif // GTEST_HAS_PARAM_TEST
56 |
57 | #endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
58 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest-typed-test2_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008 Google Inc.
2 | // All Rights Reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include
33 |
34 | #include "test/gtest-typed-test_test.h"
35 | #include "gtest/gtest.h"
36 |
37 | #if GTEST_HAS_TYPED_TEST_P
38 |
39 | // Tests that the same type-parameterized test case can be
40 | // instantiated in different translation units linked together.
41 | // (ContainerTest is also instantiated in gtest-typed-test_test.cc.)
42 | INSTANTIATE_TYPED_TEST_CASE_P(Vector, ContainerTest,
43 | testing::Types >);
44 |
45 | #endif // GTEST_HAS_TYPED_TEST_P
46 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest-typed-test_test.h:
--------------------------------------------------------------------------------
1 | // Copyright 2008 Google Inc.
2 | // All Rights Reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #ifndef GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
33 | #define GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
34 |
35 | #include "gtest/gtest.h"
36 |
37 | #if GTEST_HAS_TYPED_TEST_P
38 |
39 | using testing::Test;
40 |
41 | // For testing that the same type-parameterized test case can be
42 | // instantiated in different translation units linked together.
43 | // ContainerTest will be instantiated in both gtest-typed-test_test.cc
44 | // and gtest-typed-test2_test.cc.
45 |
46 | template
47 | class ContainerTest : public Test {
48 | };
49 |
50 | TYPED_TEST_CASE_P(ContainerTest);
51 |
52 | TYPED_TEST_P(ContainerTest, CanBeDefaultConstructed) {
53 | TypeParam container;
54 | }
55 |
56 | TYPED_TEST_P(ContainerTest, InitialSizeIsZero) {
57 | TypeParam container;
58 | EXPECT_EQ(0U, container.size());
59 | }
60 |
61 | REGISTER_TYPED_TEST_CASE_P(ContainerTest,
62 | CanBeDefaultConstructed, InitialSizeIsZero);
63 |
64 | #endif // GTEST_HAS_TYPED_TEST_P
65 |
66 | #endif // GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
67 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_all_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 | //
32 | // Tests for Google C++ Testing Framework (Google Test)
33 | //
34 | // Sometimes it's desirable to build most of Google Test's own tests
35 | // by compiling a single file. This file serves this purpose.
36 | #include "test/gtest-filepath_test.cc"
37 | #include "test/gtest-linked_ptr_test.cc"
38 | #include "test/gtest-message_test.cc"
39 | #include "test/gtest-options_test.cc"
40 | #include "test/gtest-port_test.cc"
41 | #include "test/gtest_pred_impl_unittest.cc"
42 | #include "test/gtest_prod_test.cc"
43 | #include "test/gtest-test-part_test.cc"
44 | #include "test/gtest-typed-test_test.cc"
45 | #include "test/gtest-typed-test2_test.cc"
46 | #include "test/gtest_unittest.cc"
47 | #include "test/production.cc"
48 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_break_on_failure_unittest_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | // Unit test for Google Test's break-on-failure mode.
33 | //
34 | // A user can ask Google Test to seg-fault when an assertion fails, using
35 | // either the GTEST_BREAK_ON_FAILURE environment variable or the
36 | // --gtest_break_on_failure flag. This file is used for testing such
37 | // functionality.
38 | //
39 | // This program will be invoked from a Python unit test. It is
40 | // expected to fail. Don't run it directly.
41 |
42 | #include "gtest/gtest.h"
43 |
44 | #if GTEST_OS_WINDOWS
45 | # include
46 | # include
47 | #endif
48 |
49 | namespace {
50 |
51 | // A test that's expected to fail.
52 | TEST(Foo, Bar) {
53 | EXPECT_EQ(2, 3);
54 | }
55 |
56 | #if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE
57 | // On Windows Mobile global exception handlers are not supported.
58 | LONG WINAPI ExitWithExceptionCode(
59 | struct _EXCEPTION_POINTERS* exception_pointers) {
60 | exit(exception_pointers->ExceptionRecord->ExceptionCode);
61 | }
62 | #endif
63 |
64 | } // namespace
65 |
66 | int main(int argc, char **argv) {
67 | #if GTEST_OS_WINDOWS
68 | // Suppresses display of the Windows error dialog upon encountering
69 | // a general protection fault (segment violation).
70 | SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
71 |
72 | # if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE
73 |
74 | // The default unhandled exception filter does not always exit
75 | // with the exception code as exit code - for example it exits with
76 | // 0 for EXCEPTION_ACCESS_VIOLATION and 1 for EXCEPTION_BREAKPOINT
77 | // if the application is compiled in debug mode. Thus we use our own
78 | // filter which always exits with the exception code for unhandled
79 | // exceptions.
80 | SetUnhandledExceptionFilter(ExitWithExceptionCode);
81 |
82 | # endif
83 | #endif
84 |
85 | testing::InitGoogleTest(&argc, argv);
86 |
87 | return RUN_ALL_TESTS();
88 | }
89 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_color_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | // A helper program for testing how Google Test determines whether to use
33 | // colors in the output. It prints "YES" and returns 1 if Google Test
34 | // decides to use colors, and prints "NO" and returns 0 otherwise.
35 |
36 | #include
37 |
38 | #include "gtest/gtest.h"
39 |
40 | // Indicates that this translation unit is part of Google Test's
41 | // implementation. It must come before gtest-internal-inl.h is
42 | // included, or there will be a compiler error. This trick is to
43 | // prevent a user from accidentally including gtest-internal-inl.h in
44 | // his code.
45 | #define GTEST_IMPLEMENTATION_ 1
46 | #include "src/gtest-internal-inl.h"
47 | #undef GTEST_IMPLEMENTATION_
48 |
49 | using testing::internal::ShouldUseColor;
50 |
51 | // The purpose of this is to ensure that the UnitTest singleton is
52 | // created before main() is entered, and thus that ShouldUseColor()
53 | // works the same way as in a real Google-Test-based test. We don't actual
54 | // run the TEST itself.
55 | TEST(GTestColorTest, Dummy) {
56 | }
57 |
58 | int main(int argc, char** argv) {
59 | testing::InitGoogleTest(&argc, argv);
60 |
61 | if (ShouldUseColor(true)) {
62 | // Google Test decides to use colors in the output (assuming it
63 | // goes to a TTY).
64 | printf("YES\n");
65 | return 1;
66 | } else {
67 | // Google Test decides not to use colors in the output.
68 | printf("NO\n");
69 | return 0;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_help_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | // This program is meant to be run by gtest_help_test.py. Do not run
33 | // it directly.
34 |
35 | #include "gtest/gtest.h"
36 |
37 | // When a help flag is specified, this program should skip the tests
38 | // and exit with 0; otherwise the following test will be executed,
39 | // causing this program to exit with a non-zero code.
40 | TEST(HelpFlagTest, ShouldNotBeRun) {
41 | ASSERT_TRUE(false) << "Tests shouldn't be run when --help is specified.";
42 | }
43 |
44 | #if GTEST_HAS_DEATH_TEST
45 | TEST(DeathTest, UsedByPythonScriptToDetectSupportForDeathTestsInThisBinary) {}
46 | #endif
47 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_main_unittest.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include "gtest/gtest.h"
33 |
34 | // Tests that we don't have to define main() when we link to
35 | // gtest_main instead of gtest.
36 |
37 | namespace {
38 |
39 | TEST(GTestMainTest, ShouldSucceed) {
40 | }
41 |
42 | } // namespace
43 |
44 | // We are using the main() function defined in src/gtest_main.cc, so
45 | // we don't define it here.
46 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_no_test_unittest.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // Tests that a Google Test program that has no test defined can run
31 | // successfully.
32 | //
33 | // Author: wan@google.com (Zhanyong Wan)
34 |
35 | #include "gtest/gtest.h"
36 |
37 | int main(int argc, char **argv) {
38 | testing::InitGoogleTest(&argc, argv);
39 |
40 | // An ad-hoc assertion outside of all tests.
41 | //
42 | // This serves three purposes:
43 | //
44 | // 1. It verifies that an ad-hoc assertion can be executed even if
45 | // no test is defined.
46 | // 2. It verifies that a failed ad-hoc assertion causes the test
47 | // program to fail.
48 | // 3. We had a bug where the XML output won't be generated if an
49 | // assertion is executed before RUN_ALL_TESTS() is called, even
50 | // though --gtest_output=xml is specified. This makes sure the
51 | // bug is fixed and doesn't regress.
52 | EXPECT_EQ(1, 2);
53 |
54 | // The above EXPECT_EQ() should cause RUN_ALL_TESTS() to return non-zero.
55 | return RUN_ALL_TESTS() ? 0 : 1;
56 | }
57 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_prod_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 | //
32 | // Unit test for include/gtest/gtest_prod.h.
33 |
34 | #include "gtest/gtest.h"
35 | #include "test/production.h"
36 |
37 | // Tests that private members can be accessed from a TEST declared as
38 | // a friend of the class.
39 | TEST(PrivateCodeTest, CanAccessPrivateMembers) {
40 | PrivateCode a;
41 | EXPECT_EQ(0, a.x_);
42 |
43 | a.set_x(1);
44 | EXPECT_EQ(1, a.x_);
45 | }
46 |
47 | typedef testing::Test PrivateCodeFixtureTest;
48 |
49 | // Tests that private members can be accessed from a TEST_F declared
50 | // as a friend of the class.
51 | TEST_F(PrivateCodeFixtureTest, CanAccessPrivateMembers) {
52 | PrivateCode a;
53 | EXPECT_EQ(0, a.x_);
54 |
55 | a.set_x(2);
56 | EXPECT_EQ(2, a.x_);
57 | }
58 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_shuffle_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | // Verifies that test shuffling works.
33 |
34 | #include "gtest/gtest.h"
35 |
36 | namespace {
37 |
38 | using ::testing::EmptyTestEventListener;
39 | using ::testing::InitGoogleTest;
40 | using ::testing::Message;
41 | using ::testing::Test;
42 | using ::testing::TestEventListeners;
43 | using ::testing::TestInfo;
44 | using ::testing::UnitTest;
45 | using ::testing::internal::scoped_ptr;
46 |
47 | // The test methods are empty, as the sole purpose of this program is
48 | // to print the test names before/after shuffling.
49 |
50 | class A : public Test {};
51 | TEST_F(A, A) {}
52 | TEST_F(A, B) {}
53 |
54 | TEST(ADeathTest, A) {}
55 | TEST(ADeathTest, B) {}
56 | TEST(ADeathTest, C) {}
57 |
58 | TEST(B, A) {}
59 | TEST(B, B) {}
60 | TEST(B, C) {}
61 | TEST(B, DISABLED_D) {}
62 | TEST(B, DISABLED_E) {}
63 |
64 | TEST(BDeathTest, A) {}
65 | TEST(BDeathTest, B) {}
66 |
67 | TEST(C, A) {}
68 | TEST(C, B) {}
69 | TEST(C, C) {}
70 | TEST(C, DISABLED_D) {}
71 |
72 | TEST(CDeathTest, A) {}
73 |
74 | TEST(DISABLED_D, A) {}
75 | TEST(DISABLED_D, DISABLED_B) {}
76 |
77 | // This printer prints the full test names only, starting each test
78 | // iteration with a "----" marker.
79 | class TestNamePrinter : public EmptyTestEventListener {
80 | public:
81 | virtual void OnTestIterationStart(const UnitTest& /* unit_test */,
82 | int /* iteration */) {
83 | printf("----\n");
84 | }
85 |
86 | virtual void OnTestStart(const TestInfo& test_info) {
87 | printf("%s.%s\n", test_info.test_case_name(), test_info.name());
88 | }
89 | };
90 |
91 | } // namespace
92 |
93 | int main(int argc, char **argv) {
94 | InitGoogleTest(&argc, argv);
95 |
96 | // Replaces the default printer with TestNamePrinter, which prints
97 | // the test name only.
98 | TestEventListeners& listeners = UnitTest::GetInstance()->listeners();
99 | delete listeners.Release(listeners.default_result_printer());
100 | listeners.Append(new TestNamePrinter);
101 |
102 | return RUN_ALL_TESTS();
103 | }
104 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_sole_header_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: mheule@google.com (Markus Heule)
31 | //
32 | // This test verifies that it's possible to use Google Test by including
33 | // the gtest.h header file alone.
34 |
35 | #include "gtest/gtest.h"
36 |
37 | namespace {
38 |
39 | void Subroutine() {
40 | EXPECT_EQ(42, 42);
41 | }
42 |
43 | TEST(NoFatalFailureTest, ExpectNoFatalFailure) {
44 | EXPECT_NO_FATAL_FAILURE(;);
45 | EXPECT_NO_FATAL_FAILURE(SUCCEED());
46 | EXPECT_NO_FATAL_FAILURE(Subroutine());
47 | EXPECT_NO_FATAL_FAILURE({ SUCCEED(); });
48 | }
49 |
50 | TEST(NoFatalFailureTest, AssertNoFatalFailure) {
51 | ASSERT_NO_FATAL_FAILURE(;);
52 | ASSERT_NO_FATAL_FAILURE(SUCCEED());
53 | ASSERT_NO_FATAL_FAILURE(Subroutine());
54 | ASSERT_NO_FATAL_FAILURE({ SUCCEED(); });
55 | }
56 |
57 | } // namespace
58 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_throw_on_failure_ex_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | // Tests Google Test's throw-on-failure mode with exceptions enabled.
33 |
34 | #include "gtest/gtest.h"
35 |
36 | #include
37 | #include
38 | #include
39 | #include
40 |
41 | // Prints the given failure message and exits the program with
42 | // non-zero. We use this instead of a Google Test assertion to
43 | // indicate a failure, as the latter is been tested and cannot be
44 | // relied on.
45 | void Fail(const char* msg) {
46 | printf("FAILURE: %s\n", msg);
47 | fflush(stdout);
48 | exit(1);
49 | }
50 |
51 | // Tests that an assertion failure throws a subclass of
52 | // std::runtime_error.
53 | void TestFailureThrowsRuntimeError() {
54 | testing::GTEST_FLAG(throw_on_failure) = true;
55 |
56 | // A successful assertion shouldn't throw.
57 | try {
58 | EXPECT_EQ(3, 3);
59 | } catch(...) {
60 | Fail("A successful assertion wrongfully threw.");
61 | }
62 |
63 | // A failed assertion should throw a subclass of std::runtime_error.
64 | try {
65 | EXPECT_EQ(2, 3) << "Expected failure";
66 | } catch(const std::runtime_error& e) {
67 | if (strstr(e.what(), "Expected failure") != NULL)
68 | return;
69 |
70 | printf("%s",
71 | "A failed assertion did throw an exception of the right type, "
72 | "but the message is incorrect. Instead of containing \"Expected "
73 | "failure\", it is:\n");
74 | Fail(e.what());
75 | } catch(...) {
76 | Fail("A failed assertion threw the wrong type of exception.");
77 | }
78 | Fail("A failed assertion should've thrown but didn't.");
79 | }
80 |
81 | int main(int argc, char** argv) {
82 | testing::InitGoogleTest(&argc, argv);
83 |
84 | // We want to ensure that people can use Google Test assertions in
85 | // other testing frameworks, as long as they initialize Google Test
86 | // properly and set the thrown-on-failure mode. Therefore, we don't
87 | // use Google Test's constructs for defining and running tests
88 | // (e.g. TEST and RUN_ALL_TESTS) here.
89 |
90 | TestFailureThrowsRuntimeError();
91 | return 0;
92 | }
93 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_throw_on_failure_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | // Tests Google Test's throw-on-failure mode with exceptions disabled.
33 | //
34 | // This program must be compiled with exceptions disabled. It will be
35 | // invoked by gtest_throw_on_failure_test.py, and is expected to exit
36 | // with non-zero in the throw-on-failure mode or 0 otherwise.
37 |
38 | #include "gtest/gtest.h"
39 |
40 | #include // for fflush, fprintf, NULL, etc.
41 | #include // for exit
42 | #include // for set_terminate
43 |
44 | // This terminate handler aborts the program using exit() rather than abort().
45 | // This avoids showing pop-ups on Windows systems and core dumps on Unix-like
46 | // ones.
47 | void TerminateHandler() {
48 | fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program.");
49 | fflush(NULL);
50 | exit(1);
51 | }
52 |
53 | int main(int argc, char** argv) {
54 | #if GTEST_HAS_EXCEPTIONS
55 | std::set_terminate(&TerminateHandler);
56 | #endif
57 | testing::InitGoogleTest(&argc, argv);
58 |
59 | // We want to ensure that people can use Google Test assertions in
60 | // other testing frameworks, as long as they initialize Google Test
61 | // properly and set the throw-on-failure mode. Therefore, we don't
62 | // use Google Test's constructs for defining and running tests
63 | // (e.g. TEST and RUN_ALL_TESTS) here.
64 |
65 | // In the throw-on-failure mode with exceptions disabled, this
66 | // assertion will cause the program to exit with a non-zero code.
67 | EXPECT_EQ(2, 3);
68 |
69 | // When not in the throw-on-failure mode, the control will reach
70 | // here.
71 | return 0;
72 | }
73 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_uninitialized_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # Copyright 2008, Google Inc.
4 | # All rights reserved.
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are
8 | # met:
9 | #
10 | # * Redistributions of source code must retain the above copyright
11 | # notice, this list of conditions and the following disclaimer.
12 | # * Redistributions in binary form must reproduce the above
13 | # copyright notice, this list of conditions and the following disclaimer
14 | # in the documentation and/or other materials provided with the
15 | # distribution.
16 | # * Neither the name of Google Inc. nor the names of its
17 | # contributors may be used to endorse or promote products derived from
18 | # this software without specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 | """Verifies that Google Test warns the user when not initialized properly."""
33 |
34 | __author__ = 'wan@google.com (Zhanyong Wan)'
35 |
36 | import gtest_test_utils
37 |
38 |
39 | COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_uninitialized_test_')
40 |
41 |
42 | def Assert(condition):
43 | if not condition:
44 | raise AssertionError
45 |
46 |
47 | def AssertEq(expected, actual):
48 | if expected != actual:
49 | print('Expected: %s' % (expected,))
50 | print(' Actual: %s' % (actual,))
51 | raise AssertionError
52 |
53 |
54 | def TestExitCodeAndOutput(command):
55 | """Runs the given command and verifies its exit code and output."""
56 |
57 | # Verifies that 'command' exits with code 1.
58 | p = gtest_test_utils.Subprocess(command)
59 | Assert(p.exited)
60 | AssertEq(1, p.exit_code)
61 | Assert('InitGoogleTest' in p.output)
62 |
63 |
64 | class GTestUninitializedTest(gtest_test_utils.TestCase):
65 | def testExitCodeAndOutput(self):
66 | TestExitCodeAndOutput(COMMAND)
67 |
68 |
69 | if __name__ == '__main__':
70 | gtest_test_utils.Main()
71 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_uninitialized_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include "gtest/gtest.h"
33 |
34 | TEST(DummyTest, Dummy) {
35 | // This test doesn't verify anything. We just need it to create a
36 | // realistic stage for testing the behavior of Google Test when
37 | // RUN_ALL_TESTS() is called without testing::InitGoogleTest() being
38 | // called first.
39 | }
40 |
41 | int main() {
42 | return RUN_ALL_TESTS();
43 | }
44 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_xml_outfile1_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: keith.ray@gmail.com (Keith Ray)
31 | //
32 | // gtest_xml_outfile1_test_ writes some xml via TestProperty used by
33 | // gtest_xml_outfiles_test.py
34 |
35 | #include "gtest/gtest.h"
36 |
37 | class PropertyOne : public testing::Test {
38 | protected:
39 | virtual void SetUp() {
40 | RecordProperty("SetUpProp", 1);
41 | }
42 | virtual void TearDown() {
43 | RecordProperty("TearDownProp", 1);
44 | }
45 | };
46 |
47 | TEST_F(PropertyOne, TestSomeProperties) {
48 | RecordProperty("TestSomeProperty", 1);
49 | }
50 |
--------------------------------------------------------------------------------
/lib/googletest/test/gtest_xml_outfile2_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: keith.ray@gmail.com (Keith Ray)
31 | //
32 | // gtest_xml_outfile2_test_ writes some xml via TestProperty used by
33 | // gtest_xml_outfiles_test.py
34 |
35 | #include "gtest/gtest.h"
36 |
37 | class PropertyTwo : public testing::Test {
38 | protected:
39 | virtual void SetUp() {
40 | RecordProperty("SetUpProp", 2);
41 | }
42 | virtual void TearDown() {
43 | RecordProperty("TearDownProp", 2);
44 | }
45 | };
46 |
47 | TEST_F(PropertyTwo, TestSomeProperties) {
48 | RecordProperty("TestSomeProperty", 2);
49 | }
50 |
--------------------------------------------------------------------------------
/lib/googletest/test/production.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 | //
32 | // This is part of the unit test for include/gtest/gtest_prod.h.
33 |
34 | #include "production.h"
35 |
36 | PrivateCode::PrivateCode() : x_(0) {}
37 |
--------------------------------------------------------------------------------
/lib/googletest/test/production.h:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 | //
32 | // This is part of the unit test for include/gtest/gtest_prod.h.
33 |
34 | #ifndef GTEST_TEST_PRODUCTION_H_
35 | #define GTEST_TEST_PRODUCTION_H_
36 |
37 | #include "gtest/gtest_prod.h"
38 |
39 | class PrivateCode {
40 | public:
41 | // Declares a friend test that does not use a fixture.
42 | FRIEND_TEST(PrivateCodeTest, CanAccessPrivateMembers);
43 |
44 | // Declares a friend test that uses a fixture.
45 | FRIEND_TEST(PrivateCodeFixtureTest, CanAccessPrivateMembers);
46 |
47 | PrivateCode();
48 |
49 | int x() const { return x_; }
50 | private:
51 | void set_x(int an_x) { x_ = an_x; }
52 | int x_;
53 | };
54 |
55 | #endif // GTEST_TEST_PRODUCTION_H_
56 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Config/DebugProject.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // DebugProject.xcconfig
3 | //
4 | // These are Debug Configuration project settings for the gtest framework and
5 | // examples. It is set in the "Based On:" dropdown in the "Project" info
6 | // dialog.
7 | // This file is based on the Xcode Configuration files in:
8 | // http://code.google.com/p/google-toolbox-for-mac/
9 | //
10 |
11 | #include "General.xcconfig"
12 |
13 | // No optimization
14 | GCC_OPTIMIZATION_LEVEL = 0
15 |
16 | // Deployment postprocessing is what triggers Xcode to strip, turn it off
17 | DEPLOYMENT_POSTPROCESSING = NO
18 |
19 | // Dead code stripping off
20 | DEAD_CODE_STRIPPING = NO
21 |
22 | // Debug symbols should be on obviously
23 | GCC_GENERATE_DEBUGGING_SYMBOLS = YES
24 |
25 | // Define the DEBUG macro in all debug builds
26 | OTHER_CFLAGS = $(OTHER_CFLAGS) -DDEBUG=1
27 |
28 | // These are turned off to avoid STL incompatibilities with client code
29 | // // Turns on special C++ STL checks to "encourage" good STL use
30 | // GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) _GLIBCXX_DEBUG_PEDANTIC _GLIBCXX_DEBUG _GLIBCPP_CONCEPT_CHECKS
31 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Config/FrameworkTarget.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // FrameworkTarget.xcconfig
3 | //
4 | // These are Framework target settings for the gtest framework and examples. It
5 | // is set in the "Based On:" dropdown in the "Target" info dialog.
6 | // This file is based on the Xcode Configuration files in:
7 | // http://code.google.com/p/google-toolbox-for-mac/
8 | //
9 |
10 | // Dynamic libs need to be position independent
11 | GCC_DYNAMIC_NO_PIC = NO
12 |
13 | // Dynamic libs should not have their external symbols stripped.
14 | STRIP_STYLE = non-global
15 |
16 | // Let the user install by specifying the $DSTROOT with xcodebuild
17 | SKIP_INSTALL = NO
18 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Config/General.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // General.xcconfig
3 | //
4 | // These are General configuration settings for the gtest framework and
5 | // examples.
6 | // This file is based on the Xcode Configuration files in:
7 | // http://code.google.com/p/google-toolbox-for-mac/
8 | //
9 |
10 | // Build for PPC and Intel, 32- and 64-bit
11 | ARCHS = i386 x86_64 ppc ppc64
12 |
13 | // Zerolink prevents link warnings so turn it off
14 | ZERO_LINK = NO
15 |
16 | // Prebinding considered unhelpful in 10.3 and later
17 | PREBINDING = NO
18 |
19 | // Strictest warning policy
20 | WARNING_CFLAGS = -Wall -Werror -Wendif-labels -Wnewline-eof -Wno-sign-compare -Wshadow
21 |
22 | // Work around Xcode bugs by using external strip. See:
23 | // http://lists.apple.com/archives/Xcode-users/2006/Feb/msg00050.html
24 | SEPARATE_STRIP = YES
25 |
26 | // Force C99 dialect
27 | GCC_C_LANGUAGE_STANDARD = c99
28 |
29 | // not sure why apple defaults this on, but it's pretty risky
30 | ALWAYS_SEARCH_USER_PATHS = NO
31 |
32 | // Turn on position dependent code for most cases (overridden where appropriate)
33 | GCC_DYNAMIC_NO_PIC = YES
34 |
35 | // Default SDK and minimum OS version is 10.4
36 | SDKROOT = $(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk
37 | MACOSX_DEPLOYMENT_TARGET = 10.4
38 | GCC_VERSION = 4.0
39 |
40 | // VERSIONING BUILD SETTINGS (used in Info.plist)
41 | GTEST_VERSIONINFO_ABOUT = © 2008 Google Inc.
42 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Config/ReleaseProject.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // ReleaseProject.xcconfig
3 | //
4 | // These are Release Configuration project settings for the gtest framework
5 | // and examples. It is set in the "Based On:" dropdown in the "Project" info
6 | // dialog.
7 | // This file is based on the Xcode Configuration files in:
8 | // http://code.google.com/p/google-toolbox-for-mac/
9 | //
10 |
11 | #include "General.xcconfig"
12 |
13 | // subconfig/Release.xcconfig
14 |
15 | // Optimize for space and size (Apple recommendation)
16 | GCC_OPTIMIZATION_LEVEL = s
17 |
18 | // Deploment postprocessing is what triggers Xcode to strip
19 | DEPLOYMENT_POSTPROCESSING = YES
20 |
21 | // No symbols
22 | GCC_GENERATE_DEBUGGING_SYMBOLS = NO
23 |
24 | // Dead code strip does not affect ObjC code but can help for C
25 | DEAD_CODE_STRIPPING = YES
26 |
27 | // NDEBUG is used by things like assert.h, so define it for general compat.
28 | // ASSERT going away in release tends to create unused vars.
29 | OTHER_CFLAGS = $(OTHER_CFLAGS) -DNDEBUG=1 -Wno-unused-variable
30 |
31 | // When we strip we want to strip all symbols in release, but save externals.
32 | STRIP_STYLE = all
33 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Config/StaticLibraryTarget.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // StaticLibraryTarget.xcconfig
3 | //
4 | // These are static library target settings for libgtest.a. It
5 | // is set in the "Based On:" dropdown in the "Target" info dialog.
6 | // This file is based on the Xcode Configuration files in:
7 | // http://code.google.com/p/google-toolbox-for-mac/
8 | //
9 |
10 | // Static libs can be included in bundles so make them position independent
11 | GCC_DYNAMIC_NO_PIC = NO
12 |
13 | // Static libs should not have their internal globals or external symbols
14 | // stripped.
15 | STRIP_STYLE = debugging
16 |
17 | // Let the user install by specifying the $DSTROOT with xcodebuild
18 | SKIP_INSTALL = NO
19 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Config/TestTarget.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // TestTarget.xcconfig
3 | //
4 | // These are Test target settings for the gtest framework and examples. It
5 | // is set in the "Based On:" dropdown in the "Target" info dialog.
6 |
7 | PRODUCT_NAME = $(TARGET_NAME)
8 | HEADER_SEARCH_PATHS = ../include
9 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Resources/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.google.${PRODUCT_NAME}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | GTEST_VERSIONINFO_LONG
21 | CFBundleShortVersionString
22 | GTEST_VERSIONINFO_SHORT
23 | CFBundleGetInfoString
24 | ${PRODUCT_NAME} GTEST_VERSIONINFO_LONG, ${GTEST_VERSIONINFO_ABOUT}
25 | NSHumanReadableCopyright
26 | ${GTEST_VERSIONINFO_ABOUT}
27 | CSResourcesFileMapped
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Samples/FrameworkSample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.google.gtest.${PRODUCT_NAME:identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1.0
25 | CSResourcesFileMapped
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Samples/FrameworkSample/runtests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2008, Google Inc.
4 | # All rights reserved.
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are
8 | # met:
9 | #
10 | # * Redistributions of source code must retain the above copyright
11 | # notice, this list of conditions and the following disclaimer.
12 | # * Redistributions in binary form must reproduce the above
13 | # copyright notice, this list of conditions and the following disclaimer
14 | # in the documentation and/or other materials provided with the
15 | # distribution.
16 | # * Neither the name of Google Inc. nor the names of its
17 | # contributors may be used to endorse or promote products derived from
18 | # this software without specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 | # Executes the samples and tests for the Google Test Framework.
33 |
34 | # Help the dynamic linker find the path to the libraries.
35 | export DYLD_FRAMEWORK_PATH=$BUILT_PRODUCTS_DIR
36 | export DYLD_LIBRARY_PATH=$BUILT_PRODUCTS_DIR
37 |
38 | # Create some executables.
39 | test_executables=$@
40 |
41 | # Now execute each one in turn keeping track of how many succeeded and failed.
42 | succeeded=0
43 | failed=0
44 | failed_list=()
45 | for test in ${test_executables[*]}; do
46 | "$test"
47 | result=$?
48 | if [ $result -eq 0 ]; then
49 | succeeded=$(( $succeeded + 1 ))
50 | else
51 | failed=$(( failed + 1 ))
52 | failed_list="$failed_list $test"
53 | fi
54 | done
55 |
56 | # Report the successes and failures to the console.
57 | echo "Tests complete with $succeeded successes and $failed failures."
58 | if [ $failed -ne 0 ]; then
59 | echo "The following tests failed:"
60 | echo $failed_list
61 | fi
62 | exit $failed
63 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Samples/FrameworkSample/widget.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: preston.a.jackson@gmail.com (Preston Jackson)
31 | //
32 | // Google Test - FrameworkSample
33 | // widget.cc
34 | //
35 |
36 | // Widget is a very simple class used for demonstrating the use of gtest
37 |
38 | #include "widget.h"
39 |
40 | Widget::Widget(int number, const std::string& name)
41 | : number_(number),
42 | name_(name) {}
43 |
44 | Widget::~Widget() {}
45 |
46 | float Widget::GetFloatValue() const {
47 | return number_;
48 | }
49 |
50 | int Widget::GetIntValue() const {
51 | return static_cast(number_);
52 | }
53 |
54 | std::string Widget::GetStringValue() const {
55 | return name_;
56 | }
57 |
58 | void Widget::GetCharPtrValue(char* buffer, size_t max_size) const {
59 | // Copy the char* representation of name_ into buffer, up to max_size.
60 | strncpy(buffer, name_.c_str(), max_size-1);
61 | buffer[max_size-1] = '\0';
62 | return;
63 | }
64 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Samples/FrameworkSample/widget.h:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: preston.a.jackson@gmail.com (Preston Jackson)
31 | //
32 | // Google Test - FrameworkSample
33 | // widget.h
34 | //
35 |
36 | // Widget is a very simple class used for demonstrating the use of gtest. It
37 | // simply stores two values a string and an integer, which are returned via
38 | // public accessors in multiple forms.
39 |
40 | #import
41 |
42 | class Widget {
43 | public:
44 | Widget(int number, const std::string& name);
45 | ~Widget();
46 |
47 | // Public accessors to number data
48 | float GetFloatValue() const;
49 | int GetIntValue() const;
50 |
51 | // Public accessors to the string data
52 | std::string GetStringValue() const;
53 | void GetCharPtrValue(char* buffer, size_t max_size) const;
54 |
55 | private:
56 | // Data members
57 | float number_;
58 | std::string name_;
59 | };
60 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Samples/FrameworkSample/widget_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: preston.a.jackson@gmail.com (Preston Jackson)
31 | //
32 | // Google Test - FrameworkSample
33 | // widget_test.cc
34 | //
35 |
36 | // This is a simple test file for the Widget class in the Widget.framework
37 |
38 | #include
39 | #include "gtest/gtest.h"
40 |
41 | #include
42 |
43 | // This test verifies that the constructor sets the internal state of the
44 | // Widget class correctly.
45 | TEST(WidgetInitializerTest, TestConstructor) {
46 | Widget widget(1.0f, "name");
47 | EXPECT_FLOAT_EQ(1.0f, widget.GetFloatValue());
48 | EXPECT_EQ(std::string("name"), widget.GetStringValue());
49 | }
50 |
51 | // This test verifies the conversion of the float and string values to int and
52 | // char*, respectively.
53 | TEST(WidgetInitializerTest, TestConversion) {
54 | Widget widget(1.0f, "name");
55 | EXPECT_EQ(1, widget.GetIntValue());
56 |
57 | size_t max_size = 128;
58 | char buffer[max_size];
59 | widget.GetCharPtrValue(buffer, max_size);
60 | EXPECT_STREQ("name", buffer);
61 | }
62 |
63 | // Use the Google Test main that is linked into the framework. It does something
64 | // like this:
65 | // int main(int argc, char** argv) {
66 | // testing::InitGoogleTest(&argc, argv);
67 | // return RUN_ALL_TESTS();
68 | // }
69 |
--------------------------------------------------------------------------------
/lib/googletest/xcode/Scripts/runtests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2008, Google Inc.
4 | # All rights reserved.
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are
8 | # met:
9 | #
10 | # * Redistributions of source code must retain the above copyright
11 | # notice, this list of conditions and the following disclaimer.
12 | # * Redistributions in binary form must reproduce the above
13 | # copyright notice, this list of conditions and the following disclaimer
14 | # in the documentation and/or other materials provided with the
15 | # distribution.
16 | # * Neither the name of Google Inc. nor the names of its
17 | # contributors may be used to endorse or promote products derived from
18 | # this software without specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 |
32 | # Executes the samples and tests for the Google Test Framework.
33 |
34 | # Help the dynamic linker find the path to the libraries.
35 | export DYLD_FRAMEWORK_PATH=$BUILT_PRODUCTS_DIR
36 | export DYLD_LIBRARY_PATH=$BUILT_PRODUCTS_DIR
37 |
38 | # Create some executables.
39 | test_executables=("$BUILT_PRODUCTS_DIR/gtest_unittest-framework"
40 | "$BUILT_PRODUCTS_DIR/gtest_unittest"
41 | "$BUILT_PRODUCTS_DIR/sample1_unittest-framework"
42 | "$BUILT_PRODUCTS_DIR/sample1_unittest-static")
43 |
44 | # Now execute each one in turn keeping track of how many succeeded and failed.
45 | succeeded=0
46 | failed=0
47 | failed_list=()
48 | for test in ${test_executables[*]}; do
49 | "$test"
50 | result=$?
51 | if [ $result -eq 0 ]; then
52 | succeeded=$(( $succeeded + 1 ))
53 | else
54 | failed=$(( failed + 1 ))
55 | failed_list="$failed_list $test"
56 | fi
57 | done
58 |
59 | # Report the successes and failures to the console.
60 | echo "Tests complete with $succeeded successes and $failed failures."
61 | if [ $failed -ne 0 ]; then
62 | echo "The following tests failed:"
63 | echo $failed_list
64 | fi
65 | exit $failed
66 |
--------------------------------------------------------------------------------
/linked_lists/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(linked_lists_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES main.cc)
10 | add_executable(linked_lists_run ${SOURCE_FILES})
11 |
12 | include_directories(src)
13 |
14 | add_subdirectory(src)
15 | add_subdirectory(tests)
16 |
17 | target_link_libraries(linked_lists_run linked_list_lib)
--------------------------------------------------------------------------------
/linked_lists/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(linked_list_lib)
3 |
4 | add_definitions(-std=c++11)
5 |
6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GLIBCXX_DEBUG")
7 |
8 | set(HEADER_FILES
9 | list_element.h
10 | linked_list.h
11 | )
12 |
13 | set(SOURCE_FILES
14 | linked_list.cc
15 | )
16 |
17 | add_library(linked_list_lib STATIC ${SOURCE_FILES} ${HEADER_FILES})
18 |
--------------------------------------------------------------------------------
/linked_lists/src/linked_list.h:
--------------------------------------------------------------------------------
1 | #include "list_element.h"
2 | #include
3 | #include
4 |
5 | #ifndef PROJECT_LINKEDLIST_H
6 | #define PROJECT_LINKEDLIST_H
7 |
8 | namespace jw {
9 |
10 | template
11 | class LinkedList {
12 | public:
13 | explicit LinkedList() : head_(nullptr) {}
14 | ~LinkedList();
15 | LinkedList(const LinkedList &) = delete;
16 | LinkedList &operator=(const LinkedList &) = delete;
17 | // Returns the number of data elements in list.
18 | int Size() const;
19 | // Adds an item to the front of the list
20 | void PushFront(T value);
21 | // Returns true if list is empty
22 | bool Empty() const;
23 | // Returns the value of the nth item, indexed starting at 0
24 | const T &ValueAt(int index) const;
25 | // Prints the data stored in the list
26 | void PrintDebug() const;
27 | // Remove front item, returning its value
28 | const T PopFront();
29 | // Pushes the item on the end of the list
30 | void PushBack(T value);
31 | // Removes end item and returns its value
32 | const T PopBack();
33 | // Returns value of front item.
34 | const T Front();
35 | // Returns the value of the end item.
36 | const T Back();
37 | // Insert value at index, so current item at that index is
38 | // pointed to by new item at index. Indexes start at 0.
39 | void Insert(int index, T value);
40 | // Erase node at the given index. Indexes start at 0.
41 | void Erase(int index);
42 | // Returns the value of the node at nth position from the end of the list.
43 | // Last position would be 1, second to last is 2, etc.
44 | const T ValueNFromEnd(int n);
45 | // Reverses the items stored in the list
46 | void Reverse();
47 | // removes the first item in the list with the given value
48 | void RemoveValue(T value);
49 |
50 | private:
51 | ListElement *head_;
52 | };
53 |
54 | } // namespace jw
55 |
56 | #endif // PROJECT_LINKEDLIST_H
57 |
--------------------------------------------------------------------------------
/linked_lists/src/list_element.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #ifndef PROJECT_LISTELEMENT_H
4 | #define PROJECT_LISTELEMENT_H
5 |
6 | namespace jw {
7 |
8 | template
9 | class ListElement {
10 | public:
11 | ListElement(const T &value) : next_(nullptr), data_(value) {}
12 | ~ListElement() {}
13 | ListElement(const ListElement &) = delete;
14 | ListElement &operator=(const ListElement &) = default;
15 |
16 | const T &GetData() const { return data_; }
17 | ListElement *GetNext() const { return next_; }
18 | void SetData(const T &data) { data_ = data; }
19 | void SetNext(ListElement *elem) { next_ = elem; }
20 |
21 | private:
22 | ListElement *next_;
23 | T data_;
24 | };
25 |
26 | } // namespace jw
27 |
28 | #endif // PROJECT_LISTELEMENT_H
29 |
--------------------------------------------------------------------------------
/linked_lists/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(linked_lists_tests)
2 |
3 | add_subdirectory(lib/googletest)
4 |
5 | include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
6 |
7 | add_executable(linked_list_tests list_tests.cc)
8 |
9 | target_link_libraries(linked_list_tests gtest gtest_main)
10 | target_link_libraries(linked_list_tests linked_list_lib)
11 |
--------------------------------------------------------------------------------
/linked_lists/tests/lib:
--------------------------------------------------------------------------------
1 | ../../lib
--------------------------------------------------------------------------------
/merge_sort/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(merge_sort_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES
10 | main.cc
11 | merge_sort.cc
12 | test_merge_sort.cc)
13 |
14 | add_executable(merge_sort ${SOURCE_FILES} ${HEADER_FILES})
15 |
--------------------------------------------------------------------------------
/merge_sort/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "merge_sort.h"
3 | #include "test_merge_sort.h"
4 |
5 | int main(int argc, char *argv[]) {
6 | const int num_count = 30;
7 | int original[] = {325432, 989, 547510, 3, -93, 189019, 5042, 123,
8 | 597, 42, 7506, 184, 184, 2409, 45, 824,
9 | 4, -2650, 9, 662, 3928, -170, 45358, 395,
10 | 842, 7697, 110, 14, 99, 221};
11 |
12 | int numbers[num_count];
13 |
14 | memcpy(numbers, original, sizeof numbers);
15 |
16 | printf("Sorting %d numbers...\n\n", num_count);
17 |
18 | jw::merge_sort(numbers, 0, num_count - 1);
19 |
20 | if (jw::is_sorted(numbers, num_count)) {
21 | printf("** SUCCESS! **\n");
22 | } else {
23 | printf("Uh oh - not in order.\n");
24 | }
25 |
26 | if (jw::contain_same_ints(original, numbers, num_count)) {
27 | printf("** Contain the same elements! **\n");
28 | } else {
29 | printf("Uh oh - something is missing.\n");
30 | }
31 |
32 | jw::print_ints(numbers, num_count);
33 | putchar('\n');
34 | jw::print_ints(original, num_count);
35 |
36 | return 0;
37 | }
--------------------------------------------------------------------------------
/merge_sort/merge_sort.cc:
--------------------------------------------------------------------------------
1 | namespace jw {
2 |
3 | void merge(int numbers[], int low, int mid, int high) {
4 | // temp array for holding sorted items
5 | int b[high - low - 1];
6 | int i = low;
7 | int j = mid + 1;
8 | int k = 0;
9 |
10 | // merge items from list in order
11 | while (i <= mid && j <= high) {
12 | if (numbers[i] <= numbers[j]) {
13 | b[k++] = numbers[i++];
14 | } else {
15 | b[k++] = numbers[j++];
16 | }
17 | }
18 |
19 | // copy the remaining items to tmp array
20 | while (i <= mid) b[k++] = numbers[i++];
21 | while (j <= high) b[k++] = numbers[j++];
22 |
23 | --k;
24 | while (k >= 0) {
25 | numbers[low + k] = b[k];
26 | --k;
27 | }
28 | }
29 |
30 | void merge_sort(int numbers[], int low, int high) {
31 | if (low < high) {
32 | int mid = (low + high) / 2;
33 |
34 | merge_sort(numbers, low, mid);
35 | merge_sort(numbers, mid + 1, high);
36 | merge(numbers, low, mid, high);
37 | }
38 | }
39 |
40 | } // namespace jw
--------------------------------------------------------------------------------
/merge_sort/merge_sort.h:
--------------------------------------------------------------------------------
1 | #ifndef PROJECT_MERGE_SORT_H
2 | #define PROJECT_MERGE_SORT_H
3 |
4 | namespace jw {
5 |
6 | // Overwrites the original array with merged values.
7 | void merge(int numbers[], int low, int mid, int high);
8 | // Sorts the slice of the given array from index low to index high
9 | void merge_sort(int numbers[], int low, int high);
10 |
11 | } // namespace jw
12 |
13 | #endif // PROJECT_MERGE_SORT_H
14 |
--------------------------------------------------------------------------------
/merge_sort/test_merge_sort.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "test_merge_sort.h"
3 |
4 | namespace jw {
5 |
6 | bool is_sorted(int* numbers, int count) {
7 | double last_num = -INFINITY;
8 | bool sorted = true;
9 |
10 | for (int i = 0; i < count; ++i) {
11 | if (numbers[i] < (int)last_num) {
12 | sorted = false;
13 | }
14 |
15 | last_num = numbers[i];
16 | }
17 |
18 | return sorted;
19 | }
20 |
21 | void print_ints(int numbers[], int count) {
22 | for (int i = 0; i < count; ++i) {
23 | printf("%d", numbers[i]);
24 | if (i < count - 1) {
25 | printf(", ");
26 | }
27 | }
28 | }
29 |
30 | bool contain_same_ints(int arr1[], int arr2[], int count) {
31 | for (int i = 0; i < count; ++i) {
32 | bool found = false;
33 | for (int j = 0; j < count; ++j) {
34 | if (arr1[i] == arr2[j]) {
35 | found = true;
36 | break;
37 | }
38 | }
39 | if (!found) {
40 | return false;
41 | }
42 | }
43 |
44 | return true;
45 | }
46 |
47 | } // namespace jw
48 |
--------------------------------------------------------------------------------
/merge_sort/test_merge_sort.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #ifndef PROJECT_TEST_MERGE_SORT_H
4 | #define PROJECT_TEST_MERGE_SORT_H
5 |
6 | namespace jw {
7 |
8 | // Tests that given list of integers is in sorted order
9 | bool is_sorted(int* numbers, int count);
10 | // Prints all integers in the given array
11 | void print_ints(int numbers[], int count);
12 | // Returns true if both arrays contain the same elements, regardless of order
13 | bool contain_same_ints(int arr1[], int arr2[], int count);
14 |
15 | } // namespace jw
16 |
17 | #endif // PROJECT_TEST_MERGE_SORT_H
18 |
--------------------------------------------------------------------------------
/priority_queue/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(priority_queue_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES main.cc)
10 |
11 | add_executable(priority_queue ${SOURCE_FILES} ${HEADER_FILES})
12 |
--------------------------------------------------------------------------------
/priority_queue/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "priority_queue.cc"
3 |
4 | int main(int argc, char* argv[]) {
5 | jw::PriorityQueue queue(10);
6 |
7 | assert(queue.IsEmpty());
8 | assert(queue.GetSize() == 0);
9 |
10 | queue.Insert(23, "hello");
11 | assert(!queue.IsEmpty());
12 | assert(queue.GetSize() == 1);
13 |
14 | queue.Insert(9827, "world");
15 | assert(queue.GetSize() == 2);
16 |
17 | queue.Insert(662, "C++");
18 | queue.Insert(551, "nice");
19 | queue.Insert(1221, "things");
20 | assert(queue.GetSize() == 5);
21 |
22 | jw::PQElement* max = queue.GetMax();
23 | assert(max->key_ == 9827);
24 | assert(max->value_ == "world");
25 |
26 | // queue.PrintDebug();
27 |
28 | jw::PQElement* max_element = queue.ExtractMax();
29 | assert(max_element->key_ == 9827);
30 | assert(max_element->value_ == "world");
31 | assert(queue.GetSize() == 4);
32 |
33 | max_element = queue.ExtractMax();
34 | assert(max_element->key_ == 1221);
35 | assert(max_element->value_ == "things");
36 | assert(queue.GetSize() == 3);
37 |
38 | queue.Remove(2);
39 | assert(queue.GetSize() == 2);
40 | queue.Remove(0);
41 | queue.Remove(0);
42 | assert(queue.GetSize() == 0);
43 |
44 | delete max_element;
45 |
46 | // now we'll sort an array in-place
47 |
48 | int to_sort[10] = {613, 55, 8721, 472, 94, 72, 74, 8, 61, 356};
49 | int sorted[10] = {8, 55, 61, 72, 74, 94, 356, 472, 613, 8721};
50 |
51 | jw::heapify(to_sort, 10);
52 | jw::heap_sort(to_sort, 10);
53 |
54 | assert(
55 | std::equal(std::begin(to_sort), std::end(to_sort), std::begin(sorted)));
56 |
57 | exit(EXIT_SUCCESS);
58 | }
--------------------------------------------------------------------------------
/priority_queue/priority_queue.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #ifndef PROJECT_PRIORITY_QUEUE_H
6 | #define PROJECT_PRIORITY_QUEUE_H
7 |
8 | namespace jw {
9 |
10 | typedef struct PriorityQueueElement {
11 | int key_;
12 | std::string value_;
13 | } PQElement;
14 |
15 | class PriorityQueue {
16 | public:
17 | explicit PriorityQueue(const int size);
18 | ~PriorityQueue();
19 | PriorityQueue(const PriorityQueue &) = delete;
20 | PriorityQueue &operator=(const PriorityQueue &) = delete;
21 | // Adds the given key and value to the queue
22 | void Insert(const int key, const std::string value);
23 | // Outputs the contents of the queue
24 | void PrintDebug();
25 | // Returns the maximum key and value associated with it
26 | PQElement *GetMax();
27 | // Returns the number of items stored in the queue
28 | int GetSize();
29 | // Returns true if queue is empty
30 | bool IsEmpty();
31 | // Returns the maximum key and value associated with it, removing it from the
32 | // queue
33 | PQElement *ExtractMax();
34 | // Remove the node with the given index
35 | void Remove(int index);
36 |
37 | private:
38 | int size_ = 0;
39 | int capacity_;
40 | PQElement *elements_;
41 | // Propagates the element up the tree until the parent node's heap property is
42 | // satisfied
43 | void SiftUp(int index);
44 | // Swaps 2 queue elements with the given indices
45 | void Swap(const int index1, const int index2);
46 | // Propagates the given node index down the tree until the subtree's heap
47 | // property is satisfied
48 | void SiftDown(int index);
49 | };
50 |
51 | // Turns an array into a heap
52 | void heapify(int *numbers, int count);
53 | // Sorts the given heapified array
54 | void heap_sort(int *numbers, int count);
55 | // Similar to SiftDown, but works on array of integers
56 | void percolate_down(int *numbers, int count, int index);
57 |
58 | } // namespace jw
59 |
60 | #endif // PROJECT_PRIORITY_QUEUE_H
61 |
--------------------------------------------------------------------------------
/queue_array/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(queue_array_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES main.cc)
10 | add_executable(queue_array_run ${SOURCE_FILES})
11 |
12 | include_directories(src)
13 |
14 | add_subdirectory(src)
15 | add_subdirectory(tests)
16 |
17 | target_link_libraries(queue_array_run queue_array_lib)
18 |
--------------------------------------------------------------------------------
/queue_array/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "src/queue_array.h"
5 | #include "src/queue_array.cc"
6 |
7 | int main(int argc, char *argv[]) {
8 |
9 | std::cout << "Nothing to see here. Look in tests directory." << std::endl;
10 |
11 | return EXIT_SUCCESS;
12 | }
13 |
--------------------------------------------------------------------------------
/queue_array/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(queue_array_lib)
3 |
4 | add_definitions(-std=c++11)
5 |
6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GLIBCXX_DEBUG")
7 |
8 | set(HEADER_FILES queue_array.h)
9 |
10 | set(SOURCE_FILES queue_array.cc)
11 |
12 | add_library(queue_array_lib STATIC ${SOURCE_FILES} ${HEADER_FILES})
13 |
--------------------------------------------------------------------------------
/queue_array/src/queue_array.cc:
--------------------------------------------------------------------------------
1 | #include "queue_array.h"
2 |
3 | namespace jw {
4 |
5 | template
6 | void Queue::Enqueue(T value) {
7 | if (Full()) {
8 | std::cerr << "Queue is full. Unable to enqueue." << std::endl;
9 | exit(EXIT_FAILURE);
10 | }
11 |
12 | data_[insert_] = value;
13 | insert_++;
14 | }
15 |
16 | template
17 | const T Queue::Dequeue() {
18 | if (Empty()) {
19 | std::cerr << "Queue is empty. Cannot dequeue." << std::endl;
20 | exit(EXIT_FAILURE);
21 | }
22 |
23 | T value = data_[pop_];
24 | data_[pop_] = 0;
25 | pop_++;
26 |
27 | return value;
28 | }
29 |
30 | template
31 | bool Queue::Empty() const {
32 | return insert_ == pop_;
33 | }
34 |
35 | template
36 | bool Queue::Full() const {
37 | return pop_ == (insert_ + 1) % kQueuePositions;
38 | }
39 |
40 | } // namespace jw
--------------------------------------------------------------------------------
/queue_array/src/queue_array.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #ifndef PROJECT_QUEUE_ARRAY_H
4 | #define PROJECT_QUEUE_ARRAY_H
5 |
6 | namespace jw {
7 |
8 | template
9 | class Queue {
10 | static const int kQueueCapacity = 5;
11 | static const int kQueuePositions = kQueueCapacity + 1;
12 |
13 | public:
14 | explicit Queue() : insert_(0), pop_(0) {}
15 | ~Queue() = default;
16 | Queue(const Queue &) = delete;
17 | Queue &operator=(const Queue &) = delete;
18 | // Adds value to queue.
19 | void Enqueue(T value);
20 | // Removes least recently added item from queue, returning its value.
21 | const T Dequeue();
22 | // Returns true if queue is empty.
23 | bool Empty() const;
24 | // Returns true if queue cannot accept another enqueue.
25 | bool Full() const;
26 |
27 | private:
28 | int insert_;
29 | int pop_;
30 | T data_[kQueuePositions];
31 | };
32 |
33 | } // namespace jw
34 |
35 | #endif // PROJECT_QUEUE_ARRAY_H
36 |
--------------------------------------------------------------------------------
/queue_array/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(queue_array_tests)
2 |
3 | add_executable(queue_array_tests queue_array_tests.cc)
4 |
5 | target_link_libraries(queue_array_tests queue_array_lib)
6 |
--------------------------------------------------------------------------------
/queue_array/tests/queue_array_tests.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "queue_array.cc"
5 | #include "queue_array.h"
6 |
7 | void run_all_tests();
8 | void test_empty();
9 | void test_full();
10 | void test_dequeue();
11 |
12 | int main(int argc, char *argv[]) {
13 | run_all_tests();
14 |
15 | return EXIT_SUCCESS;
16 | }
17 |
18 | void run_all_tests() {
19 | test_empty();
20 | test_full();
21 | test_dequeue();
22 | }
23 |
24 | void test_empty() {
25 | jw::Queue q;
26 |
27 | assert(q.Empty());
28 |
29 | q.Enqueue(3);
30 |
31 | assert(!q.Empty());
32 | }
33 |
34 | void test_full() {
35 | jw::Queue q;
36 |
37 | q.Enqueue(12.3);
38 | q.Enqueue(4.235);
39 | q.Enqueue(5.4);
40 | q.Enqueue(7.0);
41 | q.Enqueue(885314.32214);
42 |
43 | assert(q.Full());
44 | }
45 |
46 | void test_dequeue() {
47 | jw::Queue q;
48 |
49 | q.Enqueue(100);
50 | q.Enqueue(200);
51 | assert(q.Dequeue() == 100);
52 | q.Enqueue(300);
53 | assert(q.Dequeue() == 200);
54 | q.Enqueue(400);
55 | q.Enqueue(500);
56 | q.Enqueue(600);
57 | q.Enqueue(700);
58 | assert(q.Dequeue() == 300);
59 | assert(q.Dequeue() == 400);
60 | assert(q.Dequeue() == 500);
61 | assert(q.Dequeue() == 600);
62 | assert(q.Dequeue() == 700);
63 |
64 | assert(q.Empty());
65 | }
--------------------------------------------------------------------------------
/queue_linked_list/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(queue_llist_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES main.cc)
10 | add_executable(queue_llist_run ${SOURCE_FILES})
11 |
12 | include_directories(src)
13 |
14 | add_subdirectory(src)
15 | add_subdirectory(tests)
16 |
17 | target_link_libraries(queue_llist_run queue_llist_lib)
18 |
--------------------------------------------------------------------------------
/queue_linked_list/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "src/queue_linked_list.cc"
5 | #include "src/queue_linked_list.h"
6 |
7 | // for stdlib experiments:
8 | #include
9 | #include
10 |
11 | void stdlib_stack_experiment();
12 | void stdlib_queue_experiment();
13 |
14 | int main(int argc, char *argv[]) {
15 | std::cout << "====== Stack ========" << std::endl;
16 | stdlib_stack_experiment();
17 |
18 | std::cout << "====== Queue ========" << std::endl;
19 | stdlib_queue_experiment();
20 |
21 | return EXIT_SUCCESS;
22 | }
23 |
24 | void stdlib_stack_experiment() {
25 | auto my_stack = std::stack();
26 |
27 | std::cout << "Pushed 34" << std::endl;
28 | my_stack.push(34);
29 | int top = my_stack.top();
30 | my_stack.pop();
31 | std::cout << "Popped: " << top << std::endl;
32 |
33 | my_stack.push(123);
34 | my_stack.push(634);
35 | my_stack.push(2372);
36 | my_stack.push(134);
37 | my_stack.push(7);
38 |
39 | std::cout << "Size: " << my_stack.size() << std::endl;
40 |
41 | while (!my_stack.empty()) {
42 | std::cout << "Popping: " << my_stack.top() << std::endl;
43 | my_stack.pop();
44 | }
45 | }
46 |
47 | void stdlib_queue_experiment() {
48 | auto my_q = std::queue();
49 |
50 | std::cout << "Pushing " << std::endl;
51 | my_q.push("first!");
52 | my_q.push("second");
53 | my_q.push("third");
54 |
55 | std::cout << "Size: " << my_q.size() << std::endl;
56 |
57 | while (!my_q.empty()) {
58 | std::cout << "Popping: " << my_q.front() << std::endl;
59 | my_q.pop();
60 | }
61 | }
--------------------------------------------------------------------------------
/queue_linked_list/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(queue_llist_lib)
3 |
4 | add_definitions(-std=c++11)
5 |
6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GLIBCXX_DEBUG")
7 |
8 | set(HEADER_FILES queue_linked_list.h)
9 |
10 | set(SOURCE_FILES queue_linked_list.cc)
11 |
12 | add_library(queue_llist_lib STATIC ${SOURCE_FILES} ${HEADER_FILES})
13 |
--------------------------------------------------------------------------------
/queue_linked_list/src/list_element.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #ifndef PROJECT_LISTELEMENT_H
4 | #define PROJECT_LISTELEMENT_H
5 |
6 | namespace jw {
7 |
8 | template
9 | class ListElement {
10 | public:
11 | ListElement(const T &value) : next_(nullptr), data_(value) {}
12 | ~ListElement() {}
13 | ListElement(const ListElement &) = delete;
14 | ListElement &operator=(const ListElement &) = default;
15 |
16 | const T &GetData() const { return data_; }
17 | ListElement *GetNext() const { return next_; }
18 | void SetData(const T &data) { data_ = data; }
19 | void SetNext(ListElement *elem) { next_ = elem; }
20 |
21 | private:
22 | ListElement *next_;
23 | T data_;
24 | };
25 |
26 | } // namespace jw
27 |
28 | #endif // PROJECT_LISTELEMENT_H
29 |
--------------------------------------------------------------------------------
/queue_linked_list/src/queue_linked_list.cc:
--------------------------------------------------------------------------------
1 | #include "queue_linked_list.h"
2 |
3 | namespace jw {
4 |
5 | template
6 | Queue::~Queue() {
7 | ListElement *current = head_;
8 | ListElement *temp = head_;
9 |
10 | while (current) {
11 | temp = current;
12 | current = current->GetNext();
13 | delete temp;
14 | }
15 | }
16 |
17 | template
18 | void Queue::Enqueue(T value) {
19 | auto p = new ListElement(value);
20 | p->SetData(value);
21 | p->SetNext(nullptr);
22 |
23 | if (Empty()) {
24 | head_ = tail_ = p;
25 | } else {
26 | tail_->SetNext(p);
27 | tail_ = p;
28 | }
29 | }
30 |
31 | template
32 | const T Queue::Dequeue() {
33 | if (Empty()) {
34 | std::cerr << "Queue is empty. Cannot dequeue." << std::endl;
35 | exit(EXIT_FAILURE);
36 | }
37 |
38 | T value = head_->GetData();
39 |
40 | ListElement *temp = head_;
41 |
42 | if (head_ == tail_) {
43 | tail_ = head_->GetNext();
44 | }
45 |
46 | head_ = head_->GetNext();
47 | delete temp;
48 |
49 | return value;
50 | }
51 |
52 | template
53 | bool Queue::Empty() const {
54 | return head_ == nullptr;
55 | }
56 |
57 | template
58 | void Queue::PrintDebug() const {
59 | ListElement *current = head_;
60 |
61 | std::cout << "Queue elements: ";
62 |
63 | while (current) {
64 | std::cout << current->GetData() << " < ";
65 | current = current->GetNext();
66 | }
67 |
68 | std::cout << std::endl;
69 | }
70 |
71 | } // namespace jw
--------------------------------------------------------------------------------
/queue_linked_list/src/queue_linked_list.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "list_element.h"
3 |
4 | #ifndef PROJECT_QUEUE_LLIST_H
5 | #define PROJECT_QUEUE_LLIST_H
6 |
7 | namespace jw {
8 |
9 | template
10 | class Queue {
11 | public:
12 | explicit Queue() : head_(nullptr), tail_(nullptr) {}
13 | ~Queue();
14 | Queue(const Queue &) = delete;
15 | Queue &operator=(const Queue &) = delete;
16 | // Adds value to queue.
17 | void Enqueue(T value);
18 | // Removes least recently added item from queue, returning its value.
19 | const T Dequeue();
20 | // Returns true if queue is empty.
21 | bool Empty() const;
22 | // Outputs the items in the queue, least recently added first.
23 | void PrintDebug() const;
24 |
25 | private:
26 | ListElement *head_;
27 | ListElement *tail_;
28 | };
29 |
30 | } // namespace jw
31 |
32 | #endif // PROJECT_QUEUE_LLIST_H
33 |
--------------------------------------------------------------------------------
/queue_linked_list/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(queue_llist_tests)
2 |
3 | add_executable(queue_llist_tests queue_llist_tests.cc)
4 |
5 | target_link_libraries(queue_llist_tests queue_llist_lib)
6 |
--------------------------------------------------------------------------------
/queue_linked_list/tests/queue_llist_tests.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "queue_linked_list.cc"
5 | #include "queue_linked_list.h"
6 |
7 | void run_all_tests();
8 | void test_empty();
9 | void test_enqueue();
10 | void test_dequeue();
11 |
12 | int main(int argc, char *argv[]) {
13 | run_all_tests();
14 |
15 | return EXIT_SUCCESS;
16 | }
17 |
18 | void run_all_tests() {
19 | test_empty();
20 | test_enqueue();
21 | test_dequeue();
22 | }
23 |
24 | void test_empty() {
25 | jw::Queue q;
26 |
27 | assert(q.Empty());
28 |
29 | q.Enqueue(3);
30 |
31 | assert(!q.Empty());
32 | }
33 |
34 | void test_enqueue() {
35 | jw::Queue q;
36 |
37 | q.Enqueue(12.3);
38 | q.Enqueue(4.235);
39 | q.Enqueue(5.4);
40 | q.Enqueue(7.0);
41 | q.Enqueue(885314.32214);
42 |
43 | assert(!q.Empty());
44 | }
45 |
46 | void test_dequeue() {
47 | jw::Queue q;
48 |
49 | q.Enqueue(100);
50 | q.Enqueue(200);
51 | assert(q.Dequeue() == 100);
52 | q.Enqueue(300);
53 | assert(q.Dequeue() == 200);
54 | q.Enqueue(400);
55 | q.Enqueue(500);
56 | q.Enqueue(600);
57 | q.Enqueue(700);
58 | assert(q.Dequeue() == 300);
59 | assert(q.Dequeue() == 400);
60 | assert(q.Dequeue() == 500);
61 | assert(q.Dequeue() == 600);
62 | assert(q.Dequeue() == 700);
63 |
64 | assert(q.Empty());
65 | }
--------------------------------------------------------------------------------
/quick_sort/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(quick_sort_proj)
3 |
4 | add_definitions(-std=c++11)
5 | add_definitions(-Werror) # stop compile on warning
6 |
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
8 |
9 | set(SOURCE_FILES
10 | main.cc
11 | test_sort.cc
12 | quick_sort.cc
13 | )
14 |
15 | add_executable(quick_sort ${SOURCE_FILES} ${HEADER_FILES})
16 |
--------------------------------------------------------------------------------
/quick_sort/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | //#include // for memcpy
3 | #include "test_sort.h"
4 | #include "quick_sort.h"
5 |
6 | int main(int argc, char* argv[]) {
7 | int num_count = 30;
8 | int original[] = {325432, 989, 547510, 3, -93, 189019, 5042, 123,
9 | 597, 42, 7506, 184, 184, 2409, 45, 824,
10 | 4, -2650, 9, 662, 3928, -170, 45358, 395,
11 | 842, 7697, 110, 14, 99, 221};
12 |
13 | int numbers[num_count];
14 |
15 | memcpy(numbers, original, sizeof numbers);
16 |
17 | printf("Sorting %d numbers...\n\n", num_count);
18 |
19 | jw::quick_sort(numbers, 0, num_count - 1);
20 |
21 | if (jw::is_sorted(numbers, num_count)) {
22 | printf("** SUCCESS! **\n");
23 | } else {
24 | printf("Uh oh - not in order.\n");
25 | }
26 |
27 | if (jw::contain_same_ints(original, numbers, num_count)) {
28 | printf("** Contain the same elements! **\n");
29 | } else {
30 | printf("Uh oh - something is missing.\n");
31 | }
32 |
33 | jw::print_ints(numbers, num_count);
34 | putchar('\n');
35 | jw::print_ints(original, num_count);
36 |
37 | return 0;
38 | }
--------------------------------------------------------------------------------
/quick_sort/quick_sort.cc:
--------------------------------------------------------------------------------
1 | #include "quick_sort.h"
2 |
3 | namespace jw {
4 |
5 | void quick_sort(int numbers[], int left, int right) {
6 | if (left == right)
7 | return;
8 |
9 | srand(time(0));
10 |
11 | int i = left;
12 | int j = right;
13 | int temp = 0;
14 |
15 | int count = right - left;
16 | int pivot_mod = rand() % count;
17 | int pivot = numbers[left + pivot_mod];
18 |
19 | while (i <= j) {
20 | while (numbers[i] < pivot) ++i;
21 | while (numbers[j] > pivot) --j;
22 |
23 | if (i <= j) {
24 | if (i < j) {
25 | temp = numbers[i];
26 | numbers[i] = numbers[j];
27 | numbers[j] = temp;
28 | }
29 | ++i;
30 | --j;
31 | }
32 | }
33 |
34 | if (left < j) quick_sort(numbers, left, j);
35 | if (right > i) quick_sort(numbers, i, right);
36 | }
37 |
38 | } // namespace jw
--------------------------------------------------------------------------------
/quick_sort/quick_sort.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #ifndef PROJECT_QUICK_SORT_H
5 | #define PROJECT_QUICK_SORT_H
6 |
7 | namespace jw {
8 |
9 | void quick_sort(int numbers[], int left, int right);
10 |
11 | } // namespace jw
12 |
13 | #endif //PROJECT_QUICK_SORT_H
14 |
--------------------------------------------------------------------------------
/quick_sort/test_sort.cc:
--------------------------------------------------------------------------------
1 | #include "test_sort.h"
2 |
3 | namespace jw {
4 |
5 | bool is_sorted(int *numbers, int count) {
6 | double last_num = -INFINITY;
7 | bool sorted = true;
8 |
9 | for (int i = 0; i < count; ++i) {
10 | if (numbers[i] < (int)last_num) {
11 | sorted = false;
12 | break;
13 | }
14 |
15 | last_num = numbers[i];
16 | }
17 |
18 | return sorted;
19 | }
20 |
21 | void print_ints(int numbers[], int count) {
22 | for (int i = 0; i < count; ++i) {
23 | std::cout << numbers[i];
24 | if (i < count - 1) {
25 | std::cout << ", ";
26 | }
27 | }
28 | }
29 |
30 | bool contain_same_ints(int arr1[], int arr2[], int count) {
31 | for (int i = 0; i < count; ++i) {
32 | bool found = false;
33 | for (int j = 0; j < count; ++j) {
34 | if (arr1[i] == arr2[j]) {
35 | found = true;
36 | break;
37 | }
38 | }
39 | if (!found) {
40 | return false;
41 | }
42 | }
43 |
44 | return true;
45 | }
46 |
47 | } // namespace jw
--------------------------------------------------------------------------------
/quick_sort/test_sort.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #ifndef PROJECT_TEST_SORT_H
5 | #define PROJECT_TEST_SORT_H
6 |
7 | namespace jw {
8 |
9 | // Tests that given list of integers is in sorted order
10 | bool is_sorted(int *numbers, int count);
11 |
12 | // Prints all integers in the given array
13 | void print_ints(int numbers[], int count);
14 |
15 | // Returns true if both arrays contain the same elements, regardless of order
16 | bool contain_same_ints(int arr1[], int arr2[], int count);
17 |
18 | } // namespace jw
19 |
20 | #endif // PROJECT_TEST_SORT_H
21 |
--------------------------------------------------------------------------------
/valgrind.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | if [ $1 = "C" ]
4 | then
5 | /usr/bin/clang -ggdb main.c -std=c99 -Wall -Werror -o program && /usr/local/bin/valgrind ./program
6 | elif [ $1 = "Cpp" ]
7 | then
8 | /usr/bin/clang++ -std=c++11 -stdlib=libc++ main.cc -Wall -Werror -o program && /usr/local/bin/valgrind ./program
9 | fi
10 |
--------------------------------------------------------------------------------