This is my coursework. It is test a web server written in C++ code. It must be concurrent server using Posix threads. I have got skeleton server programe already given to me (Everyone gets that). That works perfectly. I am using linux to test and write the code.

I need to add in code to indentify the extensions:
.htm .html .jpg .jepg .txt

I have written code for .jpg only before I do rest of it as soon I know it works. I was wondering how you test it? It should work cos I have copied most of that code. I know how to test other parts of code like if GET or POST request. I test it this way:

I got file called:
test-ok.tst
in that file got:
GET /little.html HTTP/1.0
Connection: close

I also got html file called little.html.

My code file is called server.cpp. To test it I type in command line:

g++ server.cpp -lpthread

Then in new line:

./a.out 8123

Then in another command line window:

nc localhost 8123 < test-ok.tst

That test doesn't work for that bit of code cos there no .jpg to test. So where do I put .jpg to test if it works?

const char *ext=strrchr(filename,'.');
if(ext!=0 && strcmp(ext,".jpg")==0) 
{
    const char *reply="extension is .jpg\n";    
    write(1,reply,strlen(reply));
  }

Recommended Answers

All 4 Replies

I'm not sure I understand the question. Please clarify; are you wondering where to put the jpeg file itself so that it can be tested? Or are you wondering how to check if a file is a .jpg file?

1) Just call that function with a forced filename (a literal const) to test it...

(or if you meant the other question)

2) Your code looks like it should work. But if it doesn't for some reason here's what I would do

//returns true if szFilename has the szExt extension
bool CheckExt(char const * szFilename, char const * szExt)
{
if (strlen(szFilename) > strlen(szExt))
     {
          char const * szExtension = szFilename[strlen(szFilename) - strlen(szExt)];
          if (!strcmp(szExtension, szExt))
              return true;
     }
return false;
}

I'm not sure I understand the question. Please clarify; are you wondering where to put the jpeg file itself so that it can be tested? Or are you wondering how to check if a file is a .jpg file?

1st part, where to put jpg file so that it can be tested.

I think maybe 2nd part too.

I need to see if code I put in above worked, but I don't know how to test it excalty. Cos I need to put in more like .png or .gif etc. 1st I would like jpg works first before adding in others.

1st part, where to put jpg file so that it can be tested.

I think maybe 2nd part too.

I need to see if code I put in above worked, but I don't know how to test it excalty. Cos I need to put in more like .png or .gif etc. 1st I would like jpg works first before adding in others.

Then just call the function and feed it the location (in the filename string) of a known .jpg

Thanks. I'll do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.