Skip to content
Snippets Groups Projects
Commit 46f1301c authored by vcday's avatar vcday
Browse files

parser test http pass

parent 81a9772f
No related branches found
No related tags found
No related merge requests found
...@@ -138,8 +138,15 @@ string Parser::extractUrl ( string html ) ...@@ -138,8 +138,15 @@ string Parser::extractUrl ( string html )
{ {
url = ""; url = "";
unsigned long closeTag = findNext( ">", foundHref, html ); unsigned long closeTag = findNext( ">", foundHref, html );
unsigned long closeQuote = findNext( "\"", foundHref, html );
unsigned long closeSpace = findNext( " ", foundHref, html ); unsigned long closeSpace = findNext( " ", foundHref, html );
unsigned long closeUrl = 0; unsigned long closeUrl = 0;
// ends in "
// if ( closeQuote < html.size( ) && closeTag < html.size( ) && closeQuote < closeTag && closeQuote < closeSpace )
// {
// closeUrl = closeQuote;
// }
// end == ' >' // end == ' >'
if ( closeSpace < html.size( ) && closeTag < html.size( ) && closeSpace < closeTag ) if ( closeSpace < html.size( ) && closeTag < html.size( ) && closeSpace < closeTag )
{ {
...@@ -167,6 +174,10 @@ string Parser::extractUrl ( string html ) ...@@ -167,6 +174,10 @@ string Parser::extractUrl ( string html )
} }
} }
while ( !url.empty( ) && ( url.back( ) == '\"' || url.back( ) == ';' ) )
{
url.pop_back( );
}
return url; return url;
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
using namespace std; using namespace std;
void testSimple( ); void testSimple( );
void testComplex( ); void testHttp( );
void testURL( ); void testURL( );
void testBody ( ); void testBody ( );
void testExtractBody ( ); void testExtractBody ( );
...@@ -28,7 +28,7 @@ int main ( ) ...@@ -28,7 +28,7 @@ int main ( )
{ {
cout << "Testing Parser ... " << endl << endl; cout << "Testing Parser ... " << endl << endl;
testSimple( ); testSimple( );
// testComplex( ); testHttp( );
testURL( ); testURL( );
testBody ( ); testBody ( );
testExtractBody ( ); testExtractBody ( );
...@@ -90,14 +90,14 @@ void testSimple ( ) ...@@ -90,14 +90,14 @@ void testSimple ( )
cout << "Simple Test Passed!" << endl << endl; cout << "Simple Test Passed!" << endl << endl;
} }
void testComplex( ) void testHttp( )
{ {
cout << "Testing Complex: " << endl; cout << "Testing Complex: " << endl;
ProducerConsumerQueue< ParsedUrl > urlFrontierTest; ProducerConsumerQueue< ParsedUrl > urlFrontierTest;
Parser parser( &urlFrontierTest ); Parser parser( &urlFrontierTest );
ParsedUrl httpURL = ParsedUrl( "www.veronicacday.com" ); ParsedUrl httpURL = ParsedUrl( "http://veronicacday.com/" );
HttpReader reader( httpURL );
HttpReader reader( httpURL );
auto success = reader.request( ); auto success = reader.request( );
if ( !success ) if ( !success )
{ {
...@@ -107,10 +107,29 @@ void testComplex( ) ...@@ -107,10 +107,29 @@ void testComplex( )
auto dictionary = parser.execute( &reader ); auto dictionary = parser.execute( &reader );
printDictionary( *dictionary ); printDictionary( *dictionary );
urlFrontierTest.Pop( );
assert( urlFrontierTest.Pop( ).getCompleteUrl( ) == "https://trove.com/" );
assert( urlFrontierTest.Pop( ).getCompleteUrl( ) == "http://arcinnovations.xyz/" );
assert( urlFrontierTest.Pop( ).getCompleteUrl( ) == "https://gwydion.co/" );
assert( urlFrontierTest.Pop( ).getCompleteUrl( ) == "https://madeatmichigan.umich.edu/ventures/venture/gwydion/" );
assert ( dictionary != nullptr );
assert ( dictionary->size( ) == 67 );
assert ( dictionary->at( "=veronicacday.com/" ).size( ) == 1 && dictionary->at( "=veronicacday.com/" )[ 0 ] == 0 );
assert ( dictionary->at( "%serena" ).size( ) == 2 && dictionary->at( "%serena" )[ 1 ] == 24 );
assert ( dictionary->at( "#veronica" ).size( ) == 1 && dictionary->at( "#veronica" )[ 0 ] == 2 );
assert ( dictionary->at( "#dai" ).size( ) == 1 && dictionary->at( "#dai" )[ 0 ] == 3 );
assert ( dictionary->at( "%educ" ).size( ) == 1 && dictionary->at( "%educ" )[ 0 ] == 13 );
assert ( dictionary->at( "%surgeri" ).size( ) == 1 && dictionary->at( "%surgeri" )[ 0 ] == 72 );
delete dictionary; delete dictionary;
dictionary = nullptr; dictionary = nullptr;
cout << "Complex Test Passed! " << endl; cout << "Complex Test Passed! " << endl << endl;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment