TESTING COSMOLOGICAL MODELS BY GRAVITATIONAL LENSING. I. METHOD AND FIRST APPLICATIONS