He took 2 women, 1 a virgin 1 not and had them sit on a barrel of wine. While sitting on the barrel he smelled their breath. The non-virgin's breath smelled like wine (because the odor of the wine went in through the opening and out through her mouth) while the virgin's breath did not smell of wine (because the odor of the wine could not get in because she was a virgin). He then performed the same test on the newly married woman and as her breath did not smell of wine proclaimed her a virgin.
This story is brought down l'halacha in Shulchan Aruch (Even Haezer Siman 68) and is discussed by the early Acharonim.
The difficulty with the story should be obvious to everyone, we know now that this kind of test proves nothing and in fact is based on a completely false physiological premise. The fact that this story is quoted l'halacha further complicates the issue as the gemara clearly needs to be taken literally.
It seems clear to me that Chazal were relying on the medical knowledge of their day and that this test is not Torah M'Sinai.
Here a few additional relevant points which hopefully make things a little clearer.
1. Before doing the test on the woman in question R"G first tried it out on 2 women whose status he knew. There is a machlokes harishonim whether l'halacha we need to follow the example of R"G and test that the method actually works. Clearly according to those rishonim who believe we need to test first there is nothing to talk about nowadays.
2. If you look in shulchan aruch you will see that some of the acharonim already discuss that this test did not work in their day (I saw one suggestion that our wine is not strong enough), and therefore today this test is clearly not valid.
3. The Rambam when he brings down this halacha does not mention the specific test that R"G did, rather the Rambam just writes בודקין אותה, from the Rambam's omission of the one specific test found in the gemara one can possibly infer that the Rambam felt that the wine test did not work.