diff options
| -rw-r--r-- | .travis.yml | 4 | ||||
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/pugixml.cpp | 46 | ||||
| -rw-r--r-- | tests/main.cpp | 2 | ||||
| -rw-r--r-- | tests/test_compact.cpp | 34 | ||||
| -rw-r--r-- | tests/test_document.cpp | 17 | 
6 files changed, 80 insertions, 27 deletions
| diff --git a/.travis.yml b/.travis.yml index df5569c..f35124d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,6 @@ script:    - make test cxxstd=c++11 defines=$DEFINES config=release -j2    - make test cxxstd=c++98 defines=$DEFINES config=debug -j2 -after_success: bash <(curl -s https://codecov.io/bash) -f pugixml.cpp.gcov +after_success: +  - sed -e "s/#####\(.*\)\(\/\/ unreachable.*\)/    1\1\2/" -i pugixml.cpp.gcov +  - bash <(curl -s https://codecov.io/bash) -f pugixml.cpp.gcov diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a1169b..855045c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@  project(pugixml) -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.12)  option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)  option(BUILD_TESTS "Build tests" OFF) @@ -79,4 +79,4 @@ if(BUILD_TESTS)  	add_executable(check ${TEST_SOURCES})  	target_link_libraries(check pugixml)  	add_custom_command(TARGET check POST_BUILD COMMAND check WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -endif()
\ No newline at end of file +endif() diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 25606d2..ac036e3 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -357,7 +357,7 @@ PUGI__NS_BEGIN  				bucket = (bucket + probe + 1) & hashmod;  			} -			assert(false && "Hash table is full"); +			assert(false && "Hash table is full"); // unreachable  			return 0;  		} @@ -2148,7 +2148,7 @@ PUGI__NS_BEGIN  		if (encoding == encoding_latin1)  			return convert_buffer_generic(out_buffer, out_length, contents, size, latin1_decoder()); -		assert(false && "Invalid encoding"); +		assert(false && "Invalid encoding"); // unreachable  		return false;  	}  #else @@ -2253,7 +2253,7 @@ PUGI__NS_BEGIN  		if (encoding == encoding_latin1)  			return convert_buffer_latin1(out_buffer, out_length, contents, size, is_mutable); -		assert(false && "Invalid encoding"); +		assert(false && "Invalid encoding"); // unreachable  		return false;  	}  #endif @@ -2700,7 +2700,7 @@ PUGI__NS_BEGIN  		case 5: return strconv_pcdata_impl<opt_true, opt_false, opt_true>::parse;  		case 6: return strconv_pcdata_impl<opt_true, opt_true, opt_false>::parse;  		case 7: return strconv_pcdata_impl<opt_true, opt_true, opt_true>::parse; -		default: assert(false); return 0; // should not get here +		default: assert(false); return 0; // unreachable  		}  	} @@ -2877,7 +2877,7 @@ PUGI__NS_BEGIN  		case 13: return strconv_attribute_impl<opt_true>::parse_wnorm;  		case 14: return strconv_attribute_impl<opt_false>::parse_wnorm;  		case 15: return strconv_attribute_impl<opt_true>::parse_wnorm; -		default: assert(false); return 0; // should not get here +		default: assert(false); return 0; // unreachable  		}  	} @@ -3626,7 +3626,7 @@ PUGI__NS_BEGIN  		if (encoding == encoding_latin1)  			return convert_buffer_output_generic(r_u8, data, length, wchar_decoder(), latin1_writer()); -		assert(false && "Invalid encoding"); +		assert(false && "Invalid encoding"); // unreachable  		return 0;  	}  #else @@ -3665,7 +3665,7 @@ PUGI__NS_BEGIN  		if (encoding == encoding_latin1)  			return convert_buffer_output_generic(r_u8, data, length, utf8_decoder(), latin1_writer()); -		assert(false && "Invalid encoding"); +		assert(false && "Invalid encoding"); // unreachable  		return 0;  	}  #endif @@ -4192,7 +4192,7 @@ PUGI__NS_BEGIN  				break;  			default: -				assert(false && "Invalid node type"); +				assert(false && "Invalid node type"); // unreachable  		}  	} @@ -6308,7 +6308,7 @@ namespace pugi  			return _root->value && (_root->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0 ? _root->value - doc.buffer : -1;  		default: -			assert(false && "Invalid node type"); +			assert(false && "Invalid node type"); // unreachable  			return -1;  		}  	} @@ -8523,7 +8523,7 @@ PUGI__NS_BEGIN  			break;  		default: -			assert(false && "Invalid variable type"); +			assert(false && "Invalid variable type"); // unreachable  		}  	} @@ -8544,7 +8544,7 @@ PUGI__NS_BEGIN  			return lhs->set(static_cast<const xpath_variable_boolean*>(rhs)->value);  		default: -			assert(false && "Invalid variable type"); +			assert(false && "Invalid variable type"); // unreachable  			return false;  		}  	} @@ -8631,7 +8631,7 @@ PUGI__NS_BEGIN  			return *min_element(begin, end, document_order_comparator());  		default: -			assert(false && "Invalid node set type"); +			assert(false && "Invalid node set type"); // unreachable  			return xpath_node();  		}  	} @@ -9361,7 +9361,7 @@ PUGI__NS_BEGIN  				}  			} -			assert(false && "Wrong types"); +			assert(false && "Wrong types"); // unreachable  			return false;  		} @@ -9436,7 +9436,7 @@ PUGI__NS_BEGIN  			}  			else  			{ -				assert(false && "Wrong types"); +				assert(false && "Wrong types"); // unreachable  				return false;  			}  		} @@ -9654,7 +9654,7 @@ PUGI__NS_BEGIN  				break;  			default: -				assert(false && "Unknown axis"); +				assert(false && "Unknown axis"); // unreachable  			}  			return false; @@ -9849,7 +9849,7 @@ PUGI__NS_BEGIN  			}  			default: -				assert(false && "Unimplemented axis"); +				assert(false && "Unimplemented axis"); // unreachable  			}  		} @@ -9930,7 +9930,7 @@ PUGI__NS_BEGIN  			}  			default: -				assert(false && "Unimplemented axis"); +				assert(false && "Unimplemented axis"); // unreachable  			}  		} @@ -10171,7 +10171,7 @@ PUGI__NS_BEGIN  				}  				default: -					assert(false && "Wrong expression for return type boolean"); +					assert(false && "Wrong expression for return type boolean"); // unreachable  					return false;  				}  			} @@ -10306,7 +10306,7 @@ PUGI__NS_BEGIN  				}  				default: -					assert(false && "Wrong expression for return type number"); +					assert(false && "Wrong expression for return type number"); // unreachable  					return 0;  				} @@ -10596,7 +10596,7 @@ PUGI__NS_BEGIN  				}  				default: -					assert(false && "Wrong expression for return type string"); +					assert(false && "Wrong expression for return type string"); // unreachable  					return xpath_string();  				}  			} @@ -10687,7 +10687,7 @@ PUGI__NS_BEGIN  					return step_do(c, stack, eval, axis_to_type<axis_self>());  				default: -					assert(false && "Unknown axis"); +					assert(false && "Unknown axis"); // unreachable  					return xpath_node_set_raw();  				}  			} @@ -10725,7 +10725,7 @@ PUGI__NS_BEGIN  			// fallthrough  			default: -				assert(false && "Wrong expression for return type node set"); +				assert(false && "Wrong expression for return type node set"); // unreachable  				return xpath_node_set_raw();  			}  		} @@ -12067,7 +12067,7 @@ namespace pugi  			return static_cast<const impl::xpath_variable_boolean*>(this)->name;  		default: -			assert(false && "Invalid variable type"); +			assert(false && "Invalid variable type"); // unreachable  			return 0;  		}  	} diff --git a/tests/main.cpp b/tests/main.cpp index 712edda..352b58b 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -41,7 +41,7 @@ static void* custom_allocate(size_t size)  	else  	{  		void* ptr = memory_allocate(size); -		assert(ptr); +		if (!ptr) return 0;  		g_memory_total_size += memory_size(ptr);  		g_memory_total_count++; diff --git a/tests/test_compact.cpp b/tests/test_compact.cpp index f9560c9..f5dc4ee 100644 --- a/tests/test_compact.cpp +++ b/tests/test_compact.cpp @@ -111,4 +111,38 @@ TEST_XML(compact_out_of_memory_remove, "<n a='v'/>")  	CHECK_ALLOC_FAIL(CHECK(!n.remove_attribute(a)));  	CHECK_ALLOC_FAIL(CHECK(!doc.remove_child(n)));  } + +TEST_XML(compact_pointer_attribute_list, "<n a='v'/>") +{ +	xml_node n = doc.child(STR("n")); +	xml_attribute a = n.attribute(STR("a")); + +	// make sure we fill the page with node x +	for (int i = 0; i < 1000; ++i) +		doc.append_child(STR("x")); + +	// this requires extended encoding for prev_attribute_c/next_attribute +	n.append_attribute(STR("b")); + +	// this requires extended encoding for first_attribute +	n.remove_attribute(a); + +	CHECK(!n.attribute(STR("a"))); +	CHECK(n.attribute(STR("b"))); +} + +TEST_XML(compact_pointer_node_list, "<n/>") +{ +	xml_node n = doc.child(STR("n")); + +	// make sure we fill the page with node x +	// this requires extended encoding for prev_sibling_c/next_sibling +	for (int i = 0; i < 1000; ++i) +		doc.append_child(STR("x")); + +	// this requires extended encoding for first_child +	n.append_child(STR("child")); + +	CHECK(n.child(STR("child"))); +}  #endif diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 9860737..c7ceb8f 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -383,6 +383,23 @@ TEST(document_load_file_wide_out_of_memory)  	CHECK(result.status == status_out_of_memory || result.status == status_file_not_found);  } +#if defined(__linux__) || defined(__APPLE__) +TEST(document_load_file_special_folder) +{ +	xml_document doc; +	xml_parse_result result = doc.load_file("."); +	// status_out_of_memory is somewhat counter-intuitive but on Linux ftell returns LONG_MAX for directories +	CHECK(result.status == status_file_not_found || result.status == status_io_error || result.status == status_out_of_memory); +} + +TEST(document_load_file_special_device) +{ +	xml_document doc; +	xml_parse_result result = doc.load_file("/dev/tty"); +	CHECK(result.status == status_file_not_found || result.status == status_io_error); +} +#endif +  TEST_XML(document_save, "<node/>")  {  	xml_writer_string writer; | 
